Skip to content

Commit 45da835

Browse files
authored
fix odr (#18)
Co-authored-by: Artur Bać <artur@ebasoft.com.pl>
1 parent fd640c0 commit 45da835

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

fixed_lib/include/fixedmath/fixed_string.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <algorithm>
1313
#include <concepts>
14+
#include <array>
1415
#include "detail/static_call_operator_prolog.h"
1516

1617
namespace fixedmath::inline v2
@@ -69,25 +70,23 @@ namespace detail
6970

7071
inline constexpr isdigit_t isdigit;
7172

72-
namespace string
73-
{
74-
constexpr fixed_internal power[14]{
75-
28147497671066,
76-
2814749767107,
77-
281474976711,
78-
28147497671,
79-
2814749767,
80-
281474977,
81-
28147498,
82-
2814750,
83-
281475,
84-
28148,
85-
2815,
86-
281,
87-
28,
88-
3
89-
}; // 10^-1 * 2^16 (rounded down)
90-
}
73+
// 10^-1 * 2^16 (rounded down)
74+
inline constexpr std::array<fixed_internal, 14> from_string_powers{
75+
28147497671066,
76+
2814749767107,
77+
281474976711,
78+
28147497671,
79+
2814749767,
80+
281474977,
81+
28147498,
82+
2814750,
83+
281475,
84+
28148,
85+
2815,
86+
281,
87+
28,
88+
3
89+
};
9190

9291
} // namespace detail
9392

@@ -174,10 +173,10 @@ namespace func
174173
int digit{str[pos] - '0'};
175174

176175
// Add digit * current power of 10
177-
fraction += digit * detail::string::power[i];
176+
fraction += digit * detail::from_string_powers[i];
178177

179178
// Next decimal place (divide by 10)
180-
if(i == sizeof(detail::string::power) / sizeof(fixed_internal) - 1) // Stop if we've reached our precision limit
179+
if(i == detail::from_string_powers.size() - 1) // Stop if we've reached our precision limit
181180
break;
182181

183182
++pos;

0 commit comments

Comments
 (0)