File tree Expand file tree Collapse file tree 1 file changed +17
-25
lines changed Expand file tree Collapse file tree 1 file changed +17
-25
lines changed Original file line number Diff line number Diff line change @@ -31,19 +31,15 @@ struct FloatTraits<T, 8 /*64bits*/> {
31
31
32
32
template <typename TExponent>
33
33
static T make_float (T m, TExponent e) {
34
- if (e > 0 ) {
35
- for (uint8_t index = 0 ; e != 0 ; index++) {
36
- if (e & 1 )
37
- m *= positiveBinaryPowersOfTen ()[index];
38
- e >>= 1 ;
39
- }
40
- } else {
34
+ auto powersOfTen =
35
+ e > 0 ? positiveBinaryPowersOfTen () : negativeBinaryPowersOfTen ();
36
+ if (e <= 0 )
41
37
e = TExponent (-e);
42
- for ( uint8_t index = 0 ; e != 0 ; index++) {
43
- if (e & 1 )
44
- m *= negativeBinaryPowersOfTen ()[index];
45
- e >>= 1 ;
46
- }
38
+
39
+ for ( uint8_t index = 0 ; e != 0 ; index++) {
40
+ if (e & 1 )
41
+ m *= powersOfTen[index] ;
42
+ e >>= 1 ;
47
43
}
48
44
return m;
49
45
}
@@ -151,19 +147,15 @@ struct FloatTraits<T, 4 /*32bits*/> {
151
147
152
148
template <typename TExponent>
153
149
static T make_float (T m, TExponent e) {
154
- if (e > 0 ) {
155
- for (uint8_t index = 0 ; e != 0 ; index++) {
156
- if (e & 1 )
157
- m *= positiveBinaryPowersOfTen ()[index];
158
- e >>= 1 ;
159
- }
160
- } else {
161
- e = -e;
162
- for (uint8_t index = 0 ; e != 0 ; index++) {
163
- if (e & 1 )
164
- m *= negativeBinaryPowersOfTen ()[index];
165
- e >>= 1 ;
166
- }
150
+ auto powersOfTen =
151
+ e > 0 ? positiveBinaryPowersOfTen () : negativeBinaryPowersOfTen ();
152
+ if (e <= 0 )
153
+ e = TExponent (-e);
154
+
155
+ for (uint8_t index = 0 ; e != 0 ; index++) {
156
+ if (e & 1 )
157
+ m *= powersOfTen[index];
158
+ e >>= 1 ;
167
159
}
168
160
return m;
169
161
}
You can’t perform that action at this time.
0 commit comments