From fd4633eb2594a835ddc40e6f7cfeccb1590e03c9 Mon Sep 17 00:00:00 2001 From: MarenFayre <82266301+MarenFayre@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:03:53 +0100 Subject: Clean up float_fmt logic --- core/fmt/fmt.odin | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 68e498a36..26ddca0dd 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -866,23 +866,16 @@ _pad :: proc(fi: ^Info, s: string) { } _fmt_float_as :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune, float_fmt: byte) { - prec: int = 3 - if fi.prec_set { - prec = fi.prec - } + prec := fi.prec if fi.prec_set else 3 buf: [386]byte // Can return "NaN", "+Inf", "-Inf", "+", "-". str := strconv.append_float(buf[:], v, float_fmt, prec, bit_size) - assert(len(str) >= 2) - - if !fi.plus { // '+' modifier means preserve all signs. - switch { - case str[0] == 'N': // Not a "NaN" - case str[1] == 'I': // Not a "±Inf" - case str[0] == '+': // Found "+" - // Strip + sign - str = str[1:] + + if !fi.plus { + // Strip sign from "+" but not "+Inf". + if str[0] == '+' && str[1] != 'I' { + str = str[1:] } } -- cgit v1.2.3