Skip to content

Commit 86511d4

Browse files
authored
Merge pull request #2300 from MarenFayre/float-format
Clean up float_fmt logic
2 parents b0756f9 + fd4633e commit 86511d4

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

core/fmt/fmt.odin

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -866,23 +866,16 @@ _pad :: proc(fi: ^Info, s: string) {
866866
}
867867

868868
_fmt_float_as :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune, float_fmt: byte) {
869-
prec: int = 3
870-
if fi.prec_set {
871-
prec = fi.prec
872-
}
869+
prec := fi.prec if fi.prec_set else 3
873870
buf: [386]byte
874871

875872
// Can return "NaN", "+Inf", "-Inf", "+<value>", "-<value>".
876873
str := strconv.append_float(buf[:], v, float_fmt, prec, bit_size)
877-
assert(len(str) >= 2)
878-
879-
if !fi.plus { // '+' modifier means preserve all signs.
880-
switch {
881-
case str[0] == 'N': // Not a "NaN"
882-
case str[1] == 'I': // Not a "±Inf"
883-
case str[0] == '+': // Found "+<value>"
884-
// Strip + sign
885-
str = str[1:]
874+
875+
if !fi.plus {
876+
// Strip sign from "+<value>" but not "+Inf".
877+
if str[0] == '+' && str[1] != 'I' {
878+
str = str[1:]
886879
}
887880
}
888881

0 commit comments

Comments
 (0)