Skip to content

Commit

Permalink
Merge pull request #2300 from MarenFayre/float-format
Browse files Browse the repository at this point in the history
Clean up float_fmt logic
  • Loading branch information
gingerBill authored Jan 10, 2023
2 parents b0756f9 + fd4633e commit 86511d4
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions core/fmt/fmt.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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", "+<value>", "-<value>".
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 "+<value>"
// Strip + sign
str = str[1:]

if !fi.plus {
// Strip sign from "+<value>" but not "+Inf".
if str[0] == '+' && str[1] != 'I' {
str = str[1:]
}
}

Expand Down

0 comments on commit 86511d4

Please sign in to comment.