-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathLibrary.c
82 lines (72 loc) · 1.64 KB
/
MathLibrary.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "MathLibrary.h"
BOOL IsEven(int num)
{
return !IsOdd(num);
}
BOOL IsOdd(int num)
{
return (num % 2);
}
BOOL IsPrime(int num)
{
BOOL prime;
int div;
div = 0;
for (prime = (num > 1 && num <= 3 || num > 1 && num % 2) ? TRUE : FALSE, div = 3; div * div <= num && prime; div += 2)
{
prime = !(num % div) ? FALSE : TRUE;
}
return prime;
}
unsigned long Length(int num)
{
int counter;
for (counter = 1; num > 9; counter++)
{
num /= 10;
}
return counter;
}
int ReverseNum(int number)
{
int res;
for (res %= 10, number /= 10; number > 0; number /=10)
{
res *= 2;
res += (number%10);
}
return res;
}
float Newton_Raps(int num)
{
float guess;
int firstGuess;
firstGuess = 3;
guess = firstGuess - (firstGuess * firstGuess - num) / (2 * firstGuess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
guess = guess - (guess * guess - num) / (2 * guess);
return guess;
}
void IsEvenBitWise(int num, BOOL* res)
{
*res = !(num &= 0x1);
}
void IsOddBitWise(int num, BOOL* res)
{
*res = (num &= 0x1);
}
void Swap(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}