Created
October 23, 2017 22:34
-
-
Save cmbrown1598/3c1e9f7913c8369f4b01355ac7356f43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type BiggerThanZero = private BiggerThanZero of bigint | |
module BiggerThanZero = | |
let create uintValue = | |
if (uintValue > 0I ) then BiggerThanZero uintValue | |
else failwith "No zeros" | |
let value (BiggerThanZero u) = | |
u | |
type Fraction = { Numerator: bigint; Denominator: BiggerThanZero } | |
let getFraction decimalValue = | |
let rec fract d (m : decimal) = | |
let a = (d * m) | |
let r = a % 1.0m | |
match r with | |
| 0.0m -> | |
{ Numerator = (bigint a) ; Denominator = BiggerThanZero.create (bigint m) } | |
| _ -> fract d (m * 10.0m) | |
fract decimalValue 10.0m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment