aboutsummaryrefslogtreecommitdiff
path: root/core/strconv
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-12-21 17:05:24 +0000
committergingerBill <bill@gingerbill.org>2023-12-21 17:05:24 +0000
commit55f3e99f6330eb3961b35217823cdcc45b9eceb5 (patch)
treed9a3d7f633a8fdeaad92617e118e4f015f1dfa90 /core/strconv
parent509712f771a766959833bbcf8b1dd91bf3582ea2 (diff)
Fix `%g` in `fmt`, and make `%v` default to `%g` for floats
Diffstat (limited to 'core/strconv')
-rw-r--r--core/strconv/generic_float.odin9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/strconv/generic_float.odin b/core/strconv/generic_float.odin
index 70febf832..bbbf98523 100644
--- a/core/strconv/generic_float.odin
+++ b/core/strconv/generic_float.odin
@@ -2,6 +2,8 @@ package strconv
import "decimal"
+import "core:runtime"
+
Decimal_Slice :: struct {
digits: []byte,
count: int,
@@ -103,8 +105,11 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int)
}
} else {
switch fmt {
- case 'e', 'E': decimal.round(d, prec+1)
- case 'f', 'F': decimal.round(d, d.decimal_point+prec)
+ case 'e', 'E':
+ prec += 1
+ decimal.round(d, prec)
+ case 'f', 'F':
+ decimal.round(d, d.decimal_point+prec)
case 'g', 'G':
if prec == 0 {
prec = 1