mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge pull request #2300 from MarenFayre/float-format
Clean up float_fmt logic
This commit is contained in:
+5
-12
@@ -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) {
|
_fmt_float_as :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune, float_fmt: byte) {
|
||||||
prec: int = 3
|
prec := fi.prec if fi.prec_set else 3
|
||||||
if fi.prec_set {
|
|
||||||
prec = fi.prec
|
|
||||||
}
|
|
||||||
buf: [386]byte
|
buf: [386]byte
|
||||||
|
|
||||||
// Can return "NaN", "+Inf", "-Inf", "+<value>", "-<value>".
|
// Can return "NaN", "+Inf", "-Inf", "+<value>", "-<value>".
|
||||||
str := strconv.append_float(buf[:], v, float_fmt, prec, bit_size)
|
str := strconv.append_float(buf[:], v, float_fmt, prec, bit_size)
|
||||||
assert(len(str) >= 2)
|
|
||||||
|
|
||||||
if !fi.plus { // '+' modifier means preserve all signs.
|
if !fi.plus {
|
||||||
switch {
|
// Strip sign from "+<value>" but not "+Inf".
|
||||||
case str[0] == 'N': // Not a "NaN"
|
if str[0] == '+' && str[1] != 'I' {
|
||||||
case str[1] == 'I': // Not a "±Inf"
|
str = str[1:]
|
||||||
case str[0] == '+': // Found "+<value>"
|
|
||||||
// Strip + sign
|
|
||||||
str = str[1:]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user