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
|
Add:
1 + 2 = add(1, 2) (should be 3)
-3 + 4 + 5 + -6 = add(-3, 4, 5, -6) (should be 0)
3.2 + 1.47 + 6.3999 = add(3.2, 1.47, 6.3999) (should be 11.0699)
Subtract:
1 - 2 = sub(1, 2) (should be -1)
10 - -4 = sub (10, -4) (should be 14)
3.4 - 0.02 = sub (3.4, 0.02) (should be 3.38)
Multiply:
2 * 4 = mul(2, 4) (should be 8)
-4 * 6 * 3 = mul(-4, 6, 3) (should be -72)
1.5 * 3.2 = mul(1.5, 3.2) (should be 4.8)
Divide:
8 / 4 = div(8, 4) (should be 2)
-6 / 2 = div(-6, 2) (should be -3)
4.5 / 1.8 = div(4.5, 1.8) (should be 2.5)
Maths library:
absoulte value -3.2 = abs(-3.2) (should be 3.2)
arctangent of 2.3 / 1.7 = atan2(2.3, 1.7) (should be approx 0.934)
cosine of 1.047 = cos(1.047) (should be approx 0.5)
sine of 0.523 = sin(0.523) (should be approx 0.5)
exponential of 1.45 = exp(1.45) (should be approx 4.263)
integer portion of 2.532 = int(2.532) (should be 2)
logarithm of 2.718 = log(2.718) (should be approx 1.0)
square root of 36 = sqrt(36) (should be 6)
seed random number generator with 2 srand(2)
generate 3 random numbers: rand(), rand(), rand()
seed random number generator with 2 srand(2)
generate 3 random numbers: rand(), rand(), rand()
random number in range 0 to 10000 = rand(10000)
random number in range 0 to 1 = rand()
Advanced use:
#define TEN 10
#define FOUR 4
TEN + FOUR = add(TEN, FOUR) (should be 14)
(10 + 2) * 4 = mul( add(10, 2), 4) (should be 48)
cosine 60 * (pi/180) = cos( mul(60, div(M_PI, 180)) ) (should be 0.5)
|