31 #include "../../core/utilities/converters.h"
91 assert(n>0 && n <= MAX_ALLOWED_DECIMAL_POINTS);
101 return m_decimal_points;
110 m_raw_value = raw_value;
133 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
134 assert(buffer !=
nullptr);
137 char temp_buffer[MAX_DIGITS];
138 std::size_t temp_buffer_length = 0;
140 std::size_t length_fractal_part = 0;
141 bool in_fractal_part =
false;
143 for (std::size_t i = 0; i < length; i++)
145 char current_char = buffer[i];
147 if (current_char !=
'.')
149 assert(temp_buffer_length < MAX_DIGITS);
151 temp_buffer[temp_buffer_length] = current_char;
152 temp_buffer_length++;
154 if (in_fractal_part )
156 length_fractal_part++;
161 in_fractal_part =
true;
165 assert(length_fractal_part <= m_decimal_points && length_fractal_part <= MAX_ALLOWED_DECIMAL_POINTS);
167 uint64_t scale = POWERS_OF_TEN[m_decimal_points];
168 scale /=
static_cast<uint64_t
>(POWERS_OF_TEN[length_fractal_part]);
170 auto value = Converters::chars_to_unsigned_int<uint64_t>(temp_buffer, temp_buffer_length);
172 m_raw_value =
static_cast<uint64_t
>(value * scale);
187 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
188 assert(buffer !=
nullptr);
190 char temp_buffer[MAX_DIGITS];
191 Converters::unsigned_int_to_chars<uint64_t>(m_raw_value, temp_buffer);
193 std::size_t length = Converters::get_chars_length_of_uint64_t(m_raw_value);
197 if (length > m_decimal_points)
199 assert(length + 1 < MAX_DIGITS);
201 std::size_t integer_part_length = length - m_decimal_points;
204 for (std::size_t i = 0; i < integer_part_length; i++)
206 buffer[i] = temp_buffer[i];
209 buffer[integer_part_length] =
'.';
212 for (std::size_t i = 0; i < m_decimal_points; i++)
214 buffer[integer_part_length + 1 + i] = temp_buffer[integer_part_length + i];
221 assert(2 + m_decimal_points < MAX_DIGITS);
226 std::size_t max_buffer_index = 2 + m_decimal_points - 1;
228 for (std::size_t i = 0; i < length; i++)
230 buffer[max_buffer_index - i] = temp_buffer[length-1-i];
233 for (std::size_t i = 0; i < m_decimal_points-length; i++)
238 return 2 + m_decimal_points;
248 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
250 char temp_buffer[MAX_DIGITS];
251 auto length =
to_chars(temp_buffer);
252 temp_buffer[length] =
'\0';
254 std::string ret = temp_buffer;
263 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
264 assert(m_decimal_points == other.m_decimal_points);
266 return m_raw_value == other.m_raw_value;
274 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
275 assert(m_decimal_points == other.m_decimal_points);
277 return m_raw_value != other.m_raw_value;
285 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
286 assert(m_decimal_points == other.m_decimal_points);
287 return m_raw_value > other.m_raw_value;
295 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
296 assert(m_decimal_points == other.m_decimal_points);
297 return m_raw_value >= other.m_raw_value;
305 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
306 assert(m_decimal_points == other.m_decimal_points);
307 return m_raw_value < other.m_raw_value;
315 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
316 assert(m_decimal_points == other.m_decimal_points);
317 return m_raw_value <= other.m_raw_value;
321 uint64_t m_raw_value = 0;
322 uint32_t m_decimal_points = 0;
324 static constexpr
inline std::size_t MAX_DIGITS = 64;
325 static constexpr
inline std::size_t MAX_ALLOWED_DECIMAL_POINTS = 9;
327 static constexpr
inline uint64_t POWERS_OF_TEN[] =
329 UINT64_C(1), UINT64_C(10), UINT64_C(100),
330 UINT64_C(1000), UINT64_C(10000), UINT64_C(100000),
331 UINT64_C(1000000), UINT64_C(10000000), UINT64_C(100000000),
332 UINT64_C(1000000000),