From 6f6ff0e39eb6d771ef5336394079646ccdc18bd5 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 7 Nov 2017 15:44:40 +0100 Subject: Use Zarith instead of Num for computing numbers --- scTypes.ml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'scTypes.ml') diff --git a/scTypes.ml b/scTypes.ml index a222f3b..075f25d 100755 --- a/scTypes.ml +++ b/scTypes.ml @@ -85,8 +85,8 @@ module DataFormat = struct end let default_value_for: type a. a dataFormat -> a = function - | Date -> DataType.Num.nan - | Number -> DataType.Num.nan + | Date -> DataType.Num.zero + | Number -> DataType.Num.zero | Bool -> false | String -> UTF8.empty @@ -106,7 +106,7 @@ module DataFormat = struct end module Type = struct - (* Required because Num.Big_int cannot be compared with Pervasives.(=) *) + let (=) : type a b. a types -> b types -> bool = fun t1 t2 -> match t1, t2 with | Num (_, n1), Num (_, n2) -> DataType.Num.eq n1 n2 @@ -131,15 +131,18 @@ module Type = struct | Str x -> UTF8.Buffer.add_string buffer x | Bool b -> UTF8.Printf.bprintf buffer "%B" b | Num (Number, n) -> - let n = DataType.Num.to_num n in - if Num.is_integer_num n then - UTF8.Buffer.add_string buffer @@ u(Num.string_of_num n) + if DataType.Num.is_integer n then + DataType.Num.to_int n + |> string_of_int + |> UTF8.from_utf8string + |> UTF8.Buffer.add_string buffer else - let to_b = UTF8.Format.formatter_of_buffer buffer in - ignore @@ UTF8.Format.fprintf to_b "%.2f" (Num.float_of_num n); + let f = DataType.Num.to_float n + and to_b = UTF8.Format.formatter_of_buffer buffer in + ignore @@ UTF8.Format.fprintf to_b "%.2f" f; Format.pp_print_flush to_b () | Num (Date, n) -> - let y, m, d = Date.date_from_julian_day (DataType.Num.to_num n) in + let y, m, d = DataType.Date.date_from_julian_day n in UTF8.Printf.bprintf buffer "%d/%d/%d" y m d end -- cgit v1.2.3