9 #include "../../core/utilities/converters.h"
69 assert(n>0 && n <= MAX_ALLOWED_DECIMAL_POINTS);
79 return m_decimal_points;
88 m_raw_value = raw_value;
111 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
112 assert(buffer !=
nullptr);
115 char temp_buffer[MAX_DIGITS];
116 std::size_t temp_buffer_length = 0;
118 std::size_t length_fractal_part = 0;
119 bool in_fractal_part =
false;
121 for (std::size_t i = 0; i < length; i++)
123 char current_char = buffer[i];
125 if (current_char !=
'.')
127 assert(temp_buffer_length < MAX_DIGITS);
129 temp_buffer[temp_buffer_length] = current_char;
130 temp_buffer_length++;
132 if (in_fractal_part )
134 length_fractal_part++;
139 in_fractal_part =
true;
143 assert(length_fractal_part <= m_decimal_points && length_fractal_part <= MAX_ALLOWED_DECIMAL_POINTS);
145 uint64_t scale = POWERS_OF_TEN[m_decimal_points];
146 scale /=
static_cast<uint64_t
>(POWERS_OF_TEN[length_fractal_part]);
148 auto value = Converters::chars_to_unsigned_int<uint64_t>(temp_buffer, temp_buffer_length);
150 m_raw_value =
static_cast<uint64_t
>(value * scale);
165 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
166 assert(buffer !=
nullptr);
168 char temp_buffer[MAX_DIGITS];
169 Converters::unsigned_int_to_chars<uint64_t>(m_raw_value, temp_buffer);
171 std::size_t length = Converters::get_chars_length_of_uint64_t(m_raw_value);
175 if (length > m_decimal_points)
177 assert(length + 1 < MAX_DIGITS);
179 std::size_t integer_part_length = length - m_decimal_points;
182 for (std::size_t i = 0; i < integer_part_length; i++)
184 buffer[i] = temp_buffer[i];
187 buffer[integer_part_length] =
'.';
190 for (std::size_t i = 0; i < m_decimal_points; i++)
192 buffer[integer_part_length + 1 + i] = temp_buffer[integer_part_length + i];
199 assert(2 + m_decimal_points < MAX_DIGITS);
204 std::size_t max_buffer_index = 2 + m_decimal_points - 1;
206 for (std::size_t i = 0; i < length; i++)
208 buffer[max_buffer_index - i] = temp_buffer[length-1-i];
211 for (std::size_t i = 0; i < m_decimal_points-length; i++)
216 return 2 + m_decimal_points;
226 assert(m_decimal_points >0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
228 char temp_buffer[MAX_DIGITS];
229 auto length =
to_chars(temp_buffer);
230 temp_buffer[length] =
'\0';
232 std::string ret = temp_buffer;
241 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
242 assert(m_decimal_points == other.m_decimal_points);
244 return m_raw_value == other.m_raw_value;
252 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
253 assert(m_decimal_points == other.m_decimal_points);
255 return m_raw_value != other.m_raw_value;
263 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
264 assert(m_decimal_points == other.m_decimal_points);
265 return m_raw_value > other.m_raw_value;
273 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
274 assert(m_decimal_points == other.m_decimal_points);
275 return m_raw_value >= other.m_raw_value;
283 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
284 assert(m_decimal_points == other.m_decimal_points);
285 return m_raw_value < other.m_raw_value;
293 assert(m_decimal_points > 0 && m_decimal_points <= MAX_ALLOWED_DECIMAL_POINTS);
294 assert(m_decimal_points == other.m_decimal_points);
295 return m_raw_value <= other.m_raw_value;
299 uint64_t m_raw_value = 0;
300 uint32_t m_decimal_points = 0;
302 static constexpr
inline std::size_t MAX_DIGITS = 64;
303 static constexpr
inline std::size_t MAX_ALLOWED_DECIMAL_POINTS = 9;
305 static constexpr
inline uint64_t POWERS_OF_TEN[] =
307 UINT64_C(1), UINT64_C(10), UINT64_C(100),
308 UINT64_C(1000), UINT64_C(10000), UINT64_C(100000),
309 UINT64_C(1000000), UINT64_C(10000000), UINT64_C(100000000),
310 UINT64_C(1000000000),