diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-11-23 23:48:24 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 3dc9bc3a6cefa30c553c6ec21b1545db98e26b6d (patch) | |
tree | 375698480c4f21c48f1f59fed4878a78468dd2a6 /asl/format_float.cpp | |
parent | a7ebfdedeee84bd01615ad62ac448adae12787db (diff) |
Add float formatting
Diffstat (limited to 'asl/format_float.cpp')
-rw-r--r-- | asl/format_float.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
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 <cstdio>
+
+// @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));
+}
|