Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 137, Wed Jul 7 21:30:23 2010 UTC revision 138, Thu Jul 8 18:47:33 2010 UTC
# Line 11  Line 11 
11    
12      eqtype rat      eqtype rat
13    
14        val zero : rat
15    
16      val ~ : rat -> rat      val ~ : rat -> rat
17      val + : rat * rat -> rat      val + : rat * rat -> rat
18      val - : rat * rat -> rat      val - : rat * rat -> rat
# Line 42  Line 44 
44    
45      val toString : rat -> string      val toString : rat -> string
46    
47        val toReal : rat -> real
48    
49    end    end
50    
51  structure Rational :> RATIONAL =  structure Rational :> RATIONAL =
# Line 132  Line 136 
136      val max : rat * rat -> rat      val max : rat * rat -> rat
137  *)  *)
138    
     fun op / (_, 0) = raise Div  
       | op / (a, b) = if (b < 0)  
           then mkRat(~a, ~b)  
           else mkRat(a, b)  
   
139      fun fromInt n = mkRat(II.fromInt n, 1)      fun fromInt n = mkRat(II.fromInt n, 1)
140      fun fromLargeInt n = mkRat(n, 1)      fun fromLargeInt n = mkRat(n, 1)
141    
# Line 144  Line 143 
143        | toString (R{num, denom}) =        | toString (R{num, denom}) =
144            String.concat[II.toString num, "/", II.toString denom]            String.concat[II.toString num, "/", II.toString denom]
145    
146        fun toReal (R{num, denom = 1}) = Real.fromLargeInt num
147          | toReal (R{num, denom}) = Real.fromLargeInt num / Real.fromLargeInt denom
148    
149        fun op / (_, 0) = raise Div
150          | op / (a, b) = if (b < 0)
151              then mkRat(~a, ~b)
152              else mkRat(a, b)
153    
154    (* bind operators *)    (* bind operators *)
155      val ~ : rat -> rat = neg      val ~ : rat -> rat = neg
156      val op + : rat * rat -> rat = add      val op + : rat * rat -> rat = add

Legend:
Removed from v.137  
changed lines
  Added in v.138

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0