UserFacing printer forgets minus sign for decimals in (-1, 0)
pierregoutagny opened this issue · comments
Pierre GOUTAGNY commented
While trying to print Runtime.decimal
s I think I've found a bug in the user-facing printer.
Here is a code example (in OCaml) demonstrating the behaviour :
open Catala_utils
open Shared_ast
let print_decimals () =
let decimals = [1.; 0.5; 0.; -0.; -0.5; -1.] in
let m = Untyped {pos = Pos.no_pos} in
Message.emit_result "float\tQ\texpr\texpr db\tuserfacing";
List.iter
(fun f ->
let q = Q.of_float f in
let e = Expr.unbox (Expr.elit (LRat q) m) in
Message.emit_result "%s\t%s\t%a\t%a\t%a"
(string_of_float f)
(Q.to_string q)
(Print.expr ~debug:false ()) e
(Print.expr ~debug:true ()) e
(Print.UserFacing.value En) e
)
decimals;;
print_decimals ()
And the printed result:
[RESULT] float Q expr expr db userfacing
[RESULT] 1. 1 1. 1. 1.0
[RESULT] 0.5 1/2 0.5 0.5 0.5
[RESULT] 0. 0 0. 0. 0.0
[RESULT] -0. 0 0. 0. 0.0
[RESULT] -0.5 -1/2 -0.5 -0.5 0.5
[RESULT] -1. -1 -1. -1. -1.0
As you can see, -0.5
is missing its leading minus sign when using the user-facing printer. I only saw this happen for decimals between -1 and 0, so it may have to do with the fact that those numbers have an integer part of "-0" which is printed as "0".