23 end; |
23 end; |
24 |
24 |
25 structure Float : FLOAT = |
25 structure Float : FLOAT = |
26 struct |
26 struct |
27 |
27 |
28 type float = Intt.int * Intt.int; |
28 type float = integer * integer; |
29 |
29 |
30 val zero = (Intt.zero, Intt.zero); |
30 val zero = (Integer.zero, Integer.zero); |
31 |
31 |
32 fun add (a1, b1) (a2, b2) = |
32 fun add (a1, b1) (a2, b2) = |
33 if Intt.cmp (b1, b2) = LESS then |
33 if Integer.cmp (b1, b2) = LESS then |
34 (Intt.add a1 (Intt.mult a2 (Intt.exp (Intt.sub b2 b1))), b1) |
34 (a1 +% a2 *% Integer.exp (b2 -% b1), b1) |
35 else |
35 else |
36 (Intt.add (Intt.mult a1 (Intt.exp (Intt.sub b1 b2))) a2, b2); |
36 (a1 *% Integer.exp (b1 -% b2) +% a2, b2); |
37 |
37 |
38 fun sub (a1, b1) (a2, b2) = |
38 fun sub (a1, b1) (a2, b2) = |
39 if Intt.cmp (b1, b2) = LESS then |
39 if Integer.cmp (b1, b2) = LESS then |
40 (Intt.sub a1 (Intt.mult a2 (Intt.exp (Intt.sub b2 b1))), b1) |
40 (a1 -% a2 *% Integer.exp (b2 -% b1), b1) |
41 else |
41 else |
42 (Intt.sub (Intt.mult a1 (Intt.exp (Intt.sub b1 b2))) a2, b2); |
42 (a1 *% Integer.exp (b1 -% b2) -% a2, b2); |
43 |
43 |
44 fun neg (a, b) = (Intt.neg a, b); |
44 fun neg (a, b) = (Integer.neg a, b); |
45 |
45 |
46 fun mult (a1, b1) (a2, b2) = (Intt.mult a1 a2, Intt.add b1 b2); |
46 fun mult (a1, b1) (a2, b2) = (a1 *% a2, b1 +% b2); |
47 |
47 |
48 fun cmp_zero (a, b) = Intt.cmp_zero a; |
48 fun cmp_zero (a, b) = Integer.cmp_zero a; |
49 |
49 |
50 fun cmp (r, s) = cmp_zero (sub r s); |
50 fun cmp (r, s) = cmp_zero (sub r s); |
51 |
51 |
52 fun eq (r, s) = cmp (r, s) = EQUAL; |
52 fun eq (r, s) = cmp (r, s) = EQUAL; |
53 |
53 |
54 fun min r s = case cmp (r, s) of LESS => r | _ => s; |
54 fun min r s = case cmp (r, s) of LESS => r | _ => s; |
55 fun max r s = case cmp (r, s) of LESS => s | _ => r; |
55 fun max r s = case cmp (r, s) of LESS => s | _ => r; |
56 |
56 |
57 fun positive_part (a, b) = (Intt.max Intt.zero a, b); |
57 fun positive_part (a, b) = (Integer.max Integer.zero a, b); |
58 fun negative_part (a, b) = (Intt.min Intt.zero a, b); |
58 fun negative_part (a, b) = (Integer.min Integer.zero a, b); |
59 |
59 |
60 end; |
60 end; |