-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.ps
108 lines (81 loc) · 1.87 KB
/
math.ps
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Add
// ===
// int + int -> int
assert(1 + 2 == 3);
assert(type(1 + 2) == isInt);
// int + real -> real
assert(1 + 3.2 == 4.2);
assert(type(1 + 3.2) == isReal);
// real + int -> real
assert(1.3 + 3 == 4.3);
assert(type(1.3 + 3) == isReal);
// real + real -> real
assert(1.3 + 3.2 == 4.5);
assert(type(1.3 + 3.2) == isReal);
// Subtract
// ========
// int - int -> int
assert(1 - 2 == -1);
assert(type(1 - 2) == isInt);
// int - real -> real
assert(3 - 1.2 == 1.8);
assert(type(3 - 1.2) == isReal);
// real - int -> real
assert(3.5 - 2 == 1.5);
assert(type(3.5 - 2) == isReal);
// real - real -> real
assert(3.5 - 2.0 == 1.5);
assert(type(3.5 - 2.0) == isReal);
// Mulitply
// ========
// int * int -> int
assert(2 * 2 == 4);
assert(type(2 * 2) == isInt);
// int * real -> real
assert(3 * 1.2 == 3.6);
assert(type(3 * 1.2) == isReal);
// real * int -> real
assert(3.3 * 2 == 6.6);
assert(type(3.3 * 2) == isReal);
// real * real -> real
assert(3.3 * 2.0 == 6.6);
assert(type(3.3 * 2.0) == isReal);
// Divide
// ======
// int / int -> int
assert(3 / 2 == 1, "int / int -> int");
assert(type(3 / 2) == isInt);
// int / real -> real
assert(3 / 2.0 == 1.5);
assert(type(3 / 2.0) == isReal);
// real / int -> real
assert(6.6 / 2 == 3.3);
assert(type(6.6 / 2) == isReal);
// real / real -> real
assert(6.6 / 2.0 == 3.3);
assert(type(6.6 / 2.0) == isReal);
// Mod
// ===
// int / int -> int
assert(4 % 2 == 0);
assert(5 % 2 == 1);
assert(type(4 % 2) == isInt);
// Pow
// ===
// int ** int -> int
assert(2 ** 2 == 4);
assert(type(2 ** 2) == isInt);
// int ** real -> real
assert(4 ** 0.5 == 2.0);
assert(type(4 ** 0.5) == isReal);
// real ** int -> real
assert(2.0 ** 2 == 4.0);
assert(type(2.0 ** 2) == isReal);
// real ** real -> real
assert(2.0 ** 2.0 == 4.0);
assert(type(2.0 ** 2.0) == isReal);
// toInt
// =====
assert(toInt(3.2) == 3);
assert(toInt(2.5) == 3);
assert(toInt(2.9) == 3);