Skip to content

Commit 1e06f33

Browse files
committed
Better numbers text rendering, remove e+0
1 parent e697438 commit 1e06f33

File tree

5 files changed

+667
-664
lines changed

5 files changed

+667
-664
lines changed

arrayjit/lib/ndarray.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,16 @@ let log_debug_info ~from_log_level:_level _nd =
446446
: bool)]]]]
447447

448448
let concise_float ~prec v =
449-
Printf.sprintf "%.*e" prec v
449+
let s = Printf.sprintf "%.*e" prec v in
450450
(* The C99 standard requires at least two digits for the exponent, but the leading zero is a waste
451-
of space. *)
452-
|> String.substr_replace_all ~pattern:"e+0" ~with_:"e+"
453-
|> String.substr_replace_all ~pattern:"e-0" ~with_:"e-"
454-
|> String.substr_replace_all ~pattern:"e+0" ~with_:"e+"
455-
|> String.substr_replace_all ~pattern:"e-0" ~with_:"e-"
451+
of space. Also handle dangling e+ for 0.0 *)
452+
let rec loop s =
453+
let s' = String.substr_replace_first s ~pattern:"e+0" ~with_:"e+" in
454+
let s' = String.substr_replace_first s' ~pattern:"e-0" ~with_:"e-" in
455+
if String.equal s s' then s else loop s'
456+
in
457+
let s = loop s in
458+
if String.is_suffix s ~suffix:"e+" then String.sub s ~pos:0 ~len:(String.length s - 2) else s
456459

457460
(** Prints 0-based [indices] entries out of [arr], where a number between [-5] and [-1] in an axis
458461
means to print out the axis, and a non-negative number means to print out only the indexed

0 commit comments

Comments
 (0)