mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Merge pull request #2190 from colrdavidson/write_float
add floats to string builder
This commit is contained in:
@@ -299,6 +299,36 @@ write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false
|
|||||||
return
|
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
|
// 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) {
|
write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) {
|
||||||
buf: [32]byte
|
buf: [32]byte
|
||||||
|
|||||||
Reference in New Issue
Block a user