Skip to content

Instantly share code, notes, and snippets.

@cmbrown1598
Created October 23, 2017 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbrown1598/3c1e9f7913c8369f4b01355ac7356f43 to your computer and use it in GitHub Desktop.
Save cmbrown1598/3c1e9f7913c8369f4b01355ac7356f43 to your computer and use it in GitHub Desktop.
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