diff --git a/src/util/format/builder.cpp b/src/util/format/builder.cpp index 7883670..a90ee56 100644 --- a/src/util/format/builder.cpp +++ b/src/util/format/builder.cpp @@ -4,11 +4,12 @@ * SPDX-License-Identifier: MIT */ -#include // size_t -#include // setprecision -#include // defaultfloat, fixed -#include // numeric_limits -#include // stringstream +#include // min +#include // size_t +#include // setprecision +#include // defaultfloat, fixed +#include // numeric_limits +#include // stringstream #include #include @@ -26,9 +27,9 @@ void Builder::putLiteral(std::string_view literal) } } -void Builder::putF32(float number, size_t precision) const +void Builder::putF32(float number, uint8_t precision) const { - precision = (precision > std::numeric_limits::digits10) ? 6 : precision; + precision = std::min(precision, static_cast(std::numeric_limits::digits10)); std::stringstream stream; stream @@ -39,9 +40,9 @@ void Builder::putF32(float number, size_t precision) const m_builder << string; } -void Builder::putF64(double number, size_t precision) const +void Builder::putF64(double number, uint8_t precision) const { - precision = (precision > std::numeric_limits::digits10) ? 6 : precision; + precision = std::min(precision, static_cast(std::numeric_limits::digits10)); std::stringstream stream; stream diff --git a/src/util/format/builder.h b/src/util/format/builder.h index 9944937..9469e9d 100644 --- a/src/util/format/builder.h +++ b/src/util/format/builder.h @@ -7,7 +7,7 @@ #pragma once #include // size_t -#include // int32_t, uint32_t, int64_t +#include // int32_t, int64_t, uint8_t, uint32_t #include // stringstream #include @@ -26,8 +26,8 @@ public: void putU32(uint32_t number) const { m_builder << number; } // unsigned int void putI64(int64_t number) const { m_builder << number; } // long int void putU64(size_t number) const { m_builder << number; } // long unsigned int - void putF32(float number, size_t precision = 6) const; - void putF64(double number, size_t precision = 6) const; + void putF32(float number, uint8_t precision = 6) const; + void putF64(double number, uint8_t precision = 6) const; void putCharacter(char character) const { m_builder.write(&character, 1); } void putString(const std::string_view string) const { m_builder.write(string.data(), string.length()); } void putPointer(const void* pointer) const { m_builder << pointer; }