# [MLton] MLton.IntInf

**Jens Axel Søgaard
**
jensaxel@soegaard.net

*Thu, 28 Apr 2005 20:02:43 +0200*

Wesley W. Terpstra wrote:
> On Tue, Apr 26, 2005 at 09:30:23PM -0700, Stephen Weeks wrote:
>
>>>Why not also the gcdext, inverse, powm, fdiv_r_2exp, and probab_prime?
Another important operation is integer square root extraction.
Your post inspired me to look at mlton/basic/rational.fun.
datatype t = T of I.t * I.t
(* always use smallest nonnegative denominator *)
fun numerator(T(n,_)) = n
fun denominator(T(_,n)) = n
fun scale(T(p,q),T(p',q')) =
let val l = I.lcm(q,q')
in (p * (l div q'),
p' * (l div q),
l)
end
val (op +) = fn (x,y) =>
let val (p,p',l) = scale(x,y)
in T(p + p',l)
end
Since p + nq
n + p/q = ---------
q
wouldn't
val (op +) =
fn (T(n,1), T(p,q)) => T(p+n*q, q)
| (x,y) => let val (p,p',l) = scale(x,y)
in T(p + p',l)
end
be an improvement?
--
Jens Axel Søgaard