diff options
author | Pierre Letouzey <pierre.letouzey@inria.fr> | 2017-02-27 19:56:27 +0100 |
---|---|---|
committer | Jason Gross <jgross@mit.edu> | 2018-02-20 19:12:35 -0500 |
commit | 960d48790121b876e6be7ca033138f5d28eae0cb (patch) | |
tree | 9b0625075ab4ae10ecabaf3c130241007137d27e /theories/NArith | |
parent | aec63ba9c8f6840d98ba731640a786138d836343 (diff) |
Decimal: simple representation of base-10 numbers
Diffstat (limited to 'theories/NArith')
-rw-r--r-- | theories/NArith/BinNatDef.v | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/theories/NArith/BinNatDef.v b/theories/NArith/BinNatDef.v index 6771e57ad..e07758914 100644 --- a/theories/NArith/BinNatDef.v +++ b/theories/NArith/BinNatDef.v @@ -378,4 +378,22 @@ Definition iter (n:N) {A} (f:A->A) (x:A) : A := | pos p => Pos.iter f x p end. +(** Conversion with a decimal representation for printing/parsing *) + +Definition of_uint (d:Decimal.uint) := Pos.of_uint d. + +Definition of_int (d:Decimal.int) := + match Decimal.norm d with + | Decimal.Pos d => Some (Pos.of_uint d) + | Decimal.Neg _ => None + end. + +Definition to_uint n := + match n with + | 0 => Decimal.zero + | pos p => Pos.to_uint p + end. + +Definition to_int n := Decimal.Pos (to_uint n). + End N. |