add amount compare

This commit is contained in:
swrup 2026-03-03 10:45:39 +01:00 committed by Swrup
parent 4bb62e369d
commit 76662bf23c
3 changed files with 11 additions and 10 deletions

View file

@ -47,6 +47,14 @@ let make ~sign ~currency ~value ~fraction =
let currency = String.uppercase_ascii currency in
Ok { sign; currency; value; fraction }
let compare a b =
match String.equal a.currency b.currency with
| false -> Fmt.failwith "amount compare on different currencies"
| true -> (
match Int64.unsigned_compare a.value b.value with
| 0 -> Int32.unsigned_compare a.fraction b.fraction
| n -> n)
module Parser = struct
open Angstrom

View file

@ -16,6 +16,8 @@ val make :
fraction:Int32.t ->
(t, string) result
(* fail on differents currencies *)
val compare : t -> t -> int
val pp : Format.formatter -> t -> unit
val to_string : t -> string
val of_string : string -> (t, string) result

View file

@ -99,16 +99,7 @@ let make_denom_group_sorted denominations =
let open RsaDenomGroup in
let open RsaDenom in
let cmp_denom b a = Timestamp.compare a.stamp_start b.stamp_start in
let cmp_group =
let cmp_amount a b =
(* TODO amount *)
let open Amount in
match Int64.unsigned_compare a.value b.value with
| 0 -> Int32.unsigned_compare a.fraction b.fraction
| n -> n
in
fun (Rsa a) (Rsa b) -> cmp_amount a.value b.value
in
let cmp_group = fun (Rsa a) (Rsa b) -> Amount.compare a.value b.value in
let l =
l
|> List.map