aboutsummaryrefslogtreecommitdiff
path: root/theories/Init
diff options
context:
space:
mode:
authorPierre Roux2020-03-17 18:34:48 +0100
committerPierre Roux2020-03-25 12:42:54 +0100
commitb2d965f87937e503c78ce78cc9cb34bbc204c016 (patch)
tree0c0b6ac85e1fba99544e3fffd7672b530a335efd /theories/Init
parent8b99dfe028faf76c23811eaf9cee8df88d231f87 (diff)
Nicer printing for decimal constants in Q
Print 1.5 as 1.5 and not 15e-1. We choose the shortest representation with tie break to the dot notation (0.01 rather than 1e-3). The printing remains injective, i.e. 12/10 is not mixed with 120/100, the first being printed as 1.2 and the last as 1.20.
Diffstat (limited to 'theories/Init')
-rw-r--r--theories/Init/Decimal.v31
1 files changed, 31 insertions, 0 deletions
diff --git a/theories/Init/Decimal.v b/theories/Init/Decimal.v
index 10c3baa2cd..855db8bc3f 100644
--- a/theories/Init/Decimal.v
+++ b/theories/Init/Decimal.v
@@ -156,6 +156,37 @@ Definition nztail_int d :=
| Neg d => let (r, n) := nztail d in pair (Neg r) n
end.
+(** [del_head n d] removes [n] digits at beginning of [d]
+ or returns [zero] if [d] has less than [n] digits. *)
+
+Fixpoint del_head n d :=
+ match n with
+ | O => d
+ | S n =>
+ match d with
+ | Nil => zero
+ | D0 d | D1 d | D2 d | D3 d | D4 d | D5 d | D6 d | D7 d | D8 d | D9 d =>
+ del_head n d
+ end
+ end.
+
+Definition del_head_int n d :=
+ match d with
+ | Pos d => Pos (del_head n d)
+ | Neg d => Neg (del_head n d)
+ end.
+
+(** [del_tail n d] removes [n] digits at end of [d]
+ or returns [zero] if [d] has less than [n] digits. *)
+
+Fixpoint del_tail n d := rev (del_head n (rev d)).
+
+Definition del_tail_int n d :=
+ match d with
+ | Pos d => Pos (del_tail n d)
+ | Neg d => Neg (del_tail n d)
+ end.
+
Module Little.
(** Successor of little-endian numbers *)