aboutsummaryrefslogtreecommitdiff
path: root/core/strings
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-11-14 12:42:49 +0000
committerGitHub <noreply@github.com>2022-11-14 12:42:49 +0000
commit682b5fa0d36ca9074142d3f69f4178a19acb1608 (patch)
tree818ac6dfe3c0a8043cc4fbd91568e7d2f7c88d3c /core/strings
parente9e05a378324470381e8111b4a929217f624f234 (diff)
parentab00db2ebd92c9bc7dd5f55c49c1e23e4541d0eb (diff)
Merge pull request #2190 from colrdavidson/write_float
add floats to string builder
Diffstat (limited to 'core/strings')
-rw-r--r--core/strings/builder.odin30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index 0386431f1..2623ee0e7 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -299,6 +299,36 @@ write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false
return
}
+// writes a f64 value into the builder, returns the written amount of characters
+write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int) -> (n: int) {
+ buf: [384]byte
+ s := strconv.append_float(buf[:], f, fmt, prec, bit_size)
+ return write_string(b, s)
+}
+
+// writes a f16 value into the builder, returns the written amount of characters
+write_f16 :: proc(b: ^Builder, f: f16, fmt: byte) -> (n: int) {
+ buf: [384]byte
+ s := strconv.append_float(buf[:], f64(f), fmt, 2*size_of(f), 8*size_of(f))
+ return write_string(b, s)
+}
+
+// writes a f32 value into the builder, returns the written amount of characters
+write_f32 :: proc(b: ^Builder, f: f32, fmt: byte) -> (n: int) {
+ buf: [384]byte
+ s := strconv.append_float(buf[:], f64(f), fmt, 2*size_of(f), 8*size_of(f))
+ return write_string(b, s)
+}
+
+// writes a f64 value into the builder, returns the written amount of characters
+write_f64 :: proc(b: ^Builder, f: f64, fmt: byte) -> (n: int) {
+ buf: [384]byte
+ s := strconv.append_float(buf[:], f64(f), fmt, 2*size_of(f), 8*size_of(f))
+ return write_string(b, s)
+}
+
+
+
// writes a u64 value `i` in `base` = 10 into the builder, returns the written amount of characters
write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) {
buf: [32]byte