From ab00db2ebd92c9bc7dd5f55c49c1e23e4541d0eb Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 14 Nov 2022 12:37:55 +0000 Subject: [PATCH] Add `write_(f16|f32|f64)` calls --- core/strings/builder.odin | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/strings/builder.odin b/core/strings/builder.odin index e58406ee6..2623ee0e7 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -306,6 +306,29 @@ write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int) -> (n: 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