diff options
author | Maxime Dénès <mail@maximedenes.fr> | 2018-02-24 09:29:26 +0100 |
---|---|---|
committer | Maxime Dénès <mail@maximedenes.fr> | 2018-02-24 09:29:26 +0100 |
commit | 89bd76b6f6a534613b03aaa970baf513b7c9b76b (patch) | |
tree | bfba682b6121778a64fcf1f593c37e4a6674990f /theories/NArith/BinNatDef.v | |
parent | 7895d276146496648d576914aab4aded4b4a32cd (diff) | |
parent | 63da69cff704be2da61f3cd311fa7a67dca6fc51 (diff) |
Merge PR #6599: Decimals in prelude
Diffstat (limited to 'theories/NArith/BinNatDef.v')
-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. |