From 3dc9bc3a6cefa30c553c6ec21b1545db98e26b6d Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 23 Nov 2024 23:48:24 +0100 Subject: Add float formatting --- asl/format_float.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 asl/format_float.cpp (limited to 'asl/format_float.cpp') diff --git a/asl/format_float.cpp b/asl/format_float.cpp new file mode 100644 index 0000000..425586f --- /dev/null +++ b/asl/format_float.cpp @@ -0,0 +1,21 @@ +#include "asl/format.hpp" + +#include + +// @Todo Use something like ryu or dragonbox + +void asl::AslFormat(Formatter& f, float value) +{ + static constexpr isize_t kBufferLength = 64; + char buffer[kBufferLength]; + int output_length = snprintf(buffer, kBufferLength, "%f", (double)value); + f.write(string_view(buffer, output_length)); +} + +void asl::AslFormat(Formatter& f, double value) +{ + static constexpr isize_t kBufferLength = 64; + char buffer[kBufferLength]; + int output_length = snprintf(buffer, kBufferLength, "%f", value); + f.write(string_view(buffer, output_length)); +} -- cgit