Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] Diff of /trunk/src/compiler/common/rational.sml
 [diderot] / trunk / src / compiler / common / rational.sml

# Diff of /trunk/src/compiler/common/rational.sml

revision 115, Wed Jun 23 22:01:49 2010 UTC revision 118, Thu Jun 24 17:06:25 2010 UTC
# Line 31  Line 31
31      val >= : rat * rat -> bool      val >= : rat * rat -> bool
32      val < : rat * rat -> bool      val < : rat * rat -> bool
33      val <= : rat * rat -> bool      val <= : rat * rat -> bool
34    *)
35
36      val compare : rat * rat -> order      val compare : rat * rat -> order
*)
37
38      val / : LargeInt.int * LargeInt.int -> rat      val / : LargeInt.int * LargeInt.int -> rat
39
# Line 78  Line 78
78            val a2 = d1 div d            val a2 = d1 div d
79            val lcm = a1 * d1            val lcm = a1 * d1
80            in            in
81              mkRat (a2*n1 + a1*n1, lcm)              mkRat (a1*n1 + a2*n2, lcm)
82            end            end
83
84      fun sub (R{num=n1, denom=d1}, R{num=n2, denom=d2}) = let      fun sub (R{num=n1, denom=d1}, R{num=n2, denom=d2}) = let
# Line 87  Line 87
87            val a2 = d1 div d            val a2 = d1 div d
88            val lcm = a1 * d1            val lcm = a1 * d1
89            in            in
90              mkRat (a2*n1 - a1*n1, lcm)              mkRat (a1*n1 - a2*n2, lcm)
91            end            end
92
93      fun mul (R{num=n1, denom=d1}, R{num=n2, denom=d2}) =      fun mul (R{num=n1, denom=d1}, R{num=n2, denom=d2}) =
# Line 107  Line 107
107
108      fun sameSign (R{num=n1, ...}, R{num=n2, ...}) = II.sameSign(n1, n2)      fun sameSign (R{num=n1, ...}, R{num=n2, ...}) = II.sameSign(n1, n2)
109
110        fun compare (R{num=n1, denom=d1}, R{num=n2, denom=d2}) = (
111              case Int.compare(II.sign n1, II.sign n2)
112               of EQUAL =>
113                    if (d1 = d2)
114                      then II.compare(n1, n2)
115                      else let
116                        val d = gcd(d1, d2)
117                        val a1 = d2 div d
118                        val a2 = d1 div d
119                        in
120                          II.compare(a1*n1, a2*n2)
121                        end
122                | order => order
123              (* end case *))
124
125  (*  (*
126      val > : rat * rat -> bool      val > : rat * rat -> bool
127      val >= : rat * rat -> bool      val >= : rat * rat -> bool
128      val < : rat * rat -> bool      val < : rat * rat -> bool
129      val <= : rat * rat -> bool      val <= : rat * rat -> bool
130
val compare : rat * rat -> order

131      val min : rat * rat -> rat      val min : rat * rat -> rat
132      val max : rat * rat -> rat      val max : rat * rat -> rat
133  *)  *)

Legend:
 Removed from v.115 changed lines Added in v.118