This commit is contained in:
parent
a7d61ef43d
commit
25f7b9682b
1 changed files with 7 additions and 9 deletions
|
|
@ -2,7 +2,6 @@
|
|||
have a currency agnostic amount_lib.ml
|
||||
and specialize amount.ml to Config.currency??
|
||||
|
||||
no Zarith
|
||||
have safe amount arithmetic *)
|
||||
type sign =
|
||||
| Sign_plus
|
||||
|
|
@ -15,6 +14,7 @@ type t = {
|
|||
fraction: Int32.t;
|
||||
}
|
||||
|
||||
(* rm Zarith *)
|
||||
let value_upper_bound = Z.(pow (of_int 2) 52) |> Z.to_int64
|
||||
|
||||
(* TODO
|
||||
|
|
@ -24,14 +24,12 @@ let value_upper_bound = Z.(pow (of_int 2) 52) |> Z.to_int64
|
|||
let fraction_upper_bound = Int32.of_int 100_000_000
|
||||
|
||||
let make ~sign ~currency ~value ~fraction =
|
||||
let ( let* ) o f = match o with _e, false -> f () | e, true -> Error e in
|
||||
let* () = ("value is negative", value < Int64.zero) in
|
||||
let* () = ("fraction is negative", fraction < Int32.zero) in
|
||||
let* () = ("value is greater than 2^52-1", value > value_upper_bound) in
|
||||
let* () =
|
||||
("fraction has more than 8 decimal digits", fraction >= fraction_upper_bound)
|
||||
in
|
||||
Ok { sign; currency; value; fraction }
|
||||
if value < Int64.zero then Error "value is negative"
|
||||
else if fraction < Int32.zero then Error "fraction is negative"
|
||||
else if value > value_upper_bound then Error "value is greater than 2^52-1"
|
||||
else if fraction >= fraction_upper_bound then
|
||||
Error "fraction has more than 8 decimal digits"
|
||||
else Ok { sign; currency; value; fraction }
|
||||
|
||||
module Parse = struct
|
||||
open Angstrom
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue