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/ZArith | |
parent | aec63ba9c8f6840d98ba731640a786138d836343 (diff) |
Decimal: simple representation of base-10 numbers
Diffstat (limited to 'theories/ZArith')
-rw-r--r-- | theories/ZArith/BinIntDef.v | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/theories/ZArith/BinIntDef.v b/theories/ZArith/BinIntDef.v index 443667f48..a0393f318 100644 --- a/theories/ZArith/BinIntDef.v +++ b/theories/ZArith/BinIntDef.v @@ -299,6 +299,23 @@ Definition to_pos (z:Z) : positive := | _ => 1%positive end. +(** Conversion with a decimal representation for printing/parsing *) + +Definition of_uint (d:Decimal.uint) := of_N (Pos.of_uint d). + +Definition of_int (d:Decimal.int) := + match d with + | Decimal.Pos d => of_uint d + | Decimal.Neg d => opp (of_uint d) + end. + +Definition to_int n := + match n with + | 0 => Decimal.Pos Decimal.zero + | pos p => Decimal.Pos (Pos.to_uint p) + | neg p => Decimal.Neg (Pos.to_uint p) + end. + (** ** Iteration of a function By convention, iterating a negative number of times is identity. |