diff --git a/src/portableML/mosml/Arbintcore.sig b/src/portableML/mosml/Arbintcore.sig index c0e4902fe3..bb8a2b021c 100644 --- a/src/portableML/mosml/Arbintcore.sig +++ b/src/portableML/mosml/Arbintcore.sig @@ -16,6 +16,7 @@ sig val fromNat : num -> int val toInt : int -> Int.int val toNat : int -> num + val toReal : int -> real val + : (int * int) -> int val - : (int * int) -> int diff --git a/src/portableML/mosml/Arbintcore.sml b/src/portableML/mosml/Arbintcore.sml index 7c44f9877e..03e200156e 100644 --- a/src/portableML/mosml/Arbintcore.sml +++ b/src/portableML/mosml/Arbintcore.sml @@ -112,6 +112,9 @@ fun fromInt n = if (Int.<(n,0)) then (false, Arbnumcore.fromInt(Int.-(0, n))) else (true, Arbnumcore.fromInt n) +fun toReal (true,n) = Arbnumcore.toReal n + | toReal (false,n) = Real.~(Arbnumcore.toReal n) + fun min (i,j) = if i < j then i else j fun max (i,j) = if i < j then j else i diff --git a/src/portableML/mosml/Arbnumcore.sig b/src/portableML/mosml/Arbnumcore.sig index 1989a6e847..9db797d4e8 100644 --- a/src/portableML/mosml/Arbnumcore.sig +++ b/src/portableML/mosml/Arbnumcore.sig @@ -30,9 +30,9 @@ sig val fromInt : int -> num (* raises Overflow if i < 0 *) val toInt : num -> int (* raises Overflow if n > maxInt *) + val toReal : num -> real (* raises Overflow if real calcs do so; no posinf for you! *) val floor : real -> num (* raises Overflow if r < 0 *) - val toReal : num -> real val asList : num -> int list diff --git a/src/portableML/mosml/Arbnumcore.sml b/src/portableML/mosml/Arbnumcore.sml index b0526768c1..1ca679e618 100644 --- a/src/portableML/mosml/Arbnumcore.sml +++ b/src/portableML/mosml/Arbnumcore.sml @@ -475,6 +475,14 @@ in val toHexString = toBaseString (fromInt 16) end +fun toReal0 f A is = + case is of + [] => A + | i :: rest => toReal0 (Real.*(f,Real.fromInt BASE)) + (Real.+(A,Real.*(f,Real.fromInt i))) + rest +fun toReal an = toReal0 1.0 0.0 an + fun isqrt n = if n < two then n