31 lines
544 B
FSharp
31 lines
544 B
FSharp
module Fraction
|
|
|
|
open common
|
|
|
|
let reduce (n,d) =
|
|
let g = gcd(n,d)
|
|
(n/g,d/g)
|
|
|
|
let mul (n1,d1) (n2,d2) =
|
|
(n1 * n2, d1 * d2)
|
|
|
|
let reciprocal (n,d) = (d,n)
|
|
|
|
let add (n1,d1) (n2,d2) =
|
|
let f = (n1*d2 + n2*d1, d2*d1)
|
|
reduce f
|
|
|
|
let reduceI (n:bigint,d:bigint) =
|
|
let g = gcdI(n,d)
|
|
(n/g,d/g)
|
|
|
|
let mulI (n1:bigint,d1:bigint) (n2:bigint,d2:bigint) =
|
|
reduceI (n1 * n2, d1 * d2)
|
|
|
|
let reciprocalI (n:bigint,d:bigint) = (d,n)
|
|
|
|
let addI (n1:bigint,d1:bigint) (n2,d2) =
|
|
let f = (n1*d2 + n2*d1, d2*d1)
|
|
f
|
|
//reduceI f
|