Skip to content

Commit 38fbe0c

Browse files
committed
Tuning.
1 parent dc7349e commit 38fbe0c

7 files changed

Lines changed: 45 additions & 157 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ endif()
3131
if(FASTFLOAT_TEST)
3232
enable_testing()
3333
add_subdirectory(tests)
34-
endif(FASTFLOAT_SANITIZE)
34+
endif(FASTFLOAT_TEST)

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ fast_float_add_cpp_test(long_exhaustive32_64)
1414
fast_float_add_cpp_test(long_random64)
1515
fast_float_add_cpp_test(random64)
1616
fast_float_add_cpp_test(basictest)
17-
fast_float_add_cpp_test(example_test)
17+
fast_float_add_cpp_test(example_test)

tests/basictest.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,25 @@ int main() {
185185
Assert(basic_test_32bit("50.811574935913086",50.811574935913086f));
186186
Assert(basic_test_32bit("17.486443519592285",17.486443519592285f));
187187
Assert(basic_test_32bit("13.91745138168335",13.91745138168335f));
188-
Assert(basic_test_32bit("7.5464513301849365",7.5464513301849365f));
188+
Assert(basic_test_32bit("7.5464513301849365",0x1.e2f90ep+2f));
189189
Assert(basic_test_32bit("2.687217116355896",2.687217116355896f));
190-
Assert(basic_test_32bit("1.1877630352973938",1.1877630352973938f));
190+
Assert(basic_test_32bit("1.1877630352973938",0x1.30113ep+0f));
191191
Assert(basic_test_32bit("0.7622503340244293",0.7622503340244293f));
192-
Assert(basic_test_32bit("0.30531780421733856",0.30531780421733856f));
193-
Assert(basic_test_32bit("0.21791061013936996",0.21791061013936996f));
194-
Assert(basic_test_32bit("0.09289376810193062",0.09289376810193062f));
192+
Assert(basic_test_32bit("0.30531780421733856",0x1.38a53ap-2f));
193+
Assert(basic_test_32bit("0.21791061013936996",0x1.be47eap-3f));
194+
Assert(basic_test_32bit("0.09289376810193062",0x1.7c7e2ep-4f));
195195
Assert(basic_test_32bit("0.03706067614257336",0.03706067614257336f));
196196
Assert(basic_test_32bit("0.028068351559340954",0.028068351559340954f));
197-
Assert(basic_test_32bit("0.012114629615098238",0.012114629615098238f));
198-
Assert(basic_test_32bit("0.004221370676532388",0.004221370676532388f));
197+
Assert(basic_test_32bit("0.012114629615098238",0x1.8cf8e2p-7f));
198+
Assert(basic_test_32bit("0.004221370676532388",0x1.14a6dap-8f));
199199
Assert(basic_test_32bit("0.002153817447833717",0.002153817447833717f));
200-
Assert(basic_test_32bit("0.0015924838953651488",0.0015924838953651488f));
200+
Assert(basic_test_32bit("0.0015924838953651488",0x1.a175cap-10f));
201201
Assert(basic_test_32bit("0.0008602388261351734",0.0008602388261351734f));
202-
Assert(basic_test_32bit("0.00036393293703440577",0.00036393293703440577f));
202+
Assert(basic_test_32bit("0.00036393293703440577",0x1.7d9c82p-12f));
203203
Assert(basic_test_32bit("0.00013746770127909258",0.00013746770127909258));
204204
Assert(basic_test_32bit("16407.9462890625", 16407.9462890625f));
205-
Assert(basic_test_32bit("1.1754947011469036e-38", 1.1754947011469036e-38f));
206-
Assert(basic_test_32bit("7.0064923216240854e-46", 7.0064923216240854e-46f));
205+
Assert(basic_test_32bit("1.1754947011469036e-38", 0x1.000006p-126f));
206+
Assert(basic_test_32bit("7.0064923216240854e-46", 0x1p-149f));
207207
Assert(basic_test_32bit("8388614.5", 8388614.5f));
208208
Assert(basic_test_32bit("0e9999999999999999999999999999", 0));
209209
Assert(basic_test_32bit("1234456789012345678901234567890e9999999999999999999999999999", std::numeric_limits<float>::infinity()));
@@ -218,9 +218,9 @@ int main() {
218218
Assert(basic_test_32bit(1.4012984643e-45f));
219219
Assert(basic_test_32bit(1.1754942107e-38f));
220220
Assert(basic_test_32bit(1.1754943508e-45f));
221-
Assert(basic_test_32bit(3.4028234664e38f));
222-
Assert(basic_test_32bit(3.4028234665e38f));
223-
Assert(basic_test_32bit(3.4028234666e38f));
221+
Assert(basic_test_32bit("3.4028234664e38", 0x1.fffffep+127f));
222+
Assert(basic_test_32bit("3.4028234665e38", 0x1.fffffep+127f));
223+
Assert(basic_test_32bit("3.4028234666e38", 0x1.fffffep+127f));
224224
Assert(basic_test_32bit("0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625", 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625));
225225
Assert(basic_test_32bit("0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125));
226226
Assert(basic_test_32bit("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875));

tests/long_random64.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ template <typename T> char *to_string(T d, char *buffer) {
1010
return buffer + written;
1111
}
1212

13-
static __uint128_t g_lehmer64_state;
13+
static fast_float::value128 g_lehmer64_state;
1414

1515
/**
1616
* D. H. Lehmer, Mathematical methods in large-scale computing units.
@@ -24,11 +24,16 @@ static __uint128_t g_lehmer64_state;
2424
* Society 68.225 (1999): 249-260.
2525
*/
2626

27-
static inline void lehmer64_seed(uint64_t seed) { g_lehmer64_state = seed; }
27+
static inline void lehmer64_seed(uint64_t seed) {
28+
g_lehmer64_state.high = 0;
29+
g_lehmer64_state.low = seed;
30+
}
2831

2932
static inline uint64_t lehmer64() {
30-
g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
31-
return uint64_t(g_lehmer64_state >> 64);
33+
fast_float::value128 v = fast_float::full_multiplication(g_lehmer64_state.low,UINT64_C(0xda942042e4dd58b5));
34+
v.high += g_lehmer64_state.high * UINT64_C(0xda942042e4dd58b5);
35+
g_lehmer64_state = v;
36+
return v.high;
3237
}
3338

3439
size_t errors;

tests/random64.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ template <typename T> char *to_string(T d, char *buffer) {
1010
return buffer + written;
1111
}
1212

13-
static __uint128_t g_lehmer64_state;
13+
14+
static fast_float::value128 g_lehmer64_state;
1415

1516
/**
1617
* D. H. Lehmer, Mathematical methods in large-scale computing units.
@@ -24,11 +25,16 @@ static __uint128_t g_lehmer64_state;
2425
* Society 68.225 (1999): 249-260.
2526
*/
2627

27-
static inline void lehmer64_seed(uint64_t seed) { g_lehmer64_state = seed; }
28+
static inline void lehmer64_seed(uint64_t seed) {
29+
g_lehmer64_state.high = 0;
30+
g_lehmer64_state.low = seed;
31+
}
2832

2933
static inline uint64_t lehmer64() {
30-
g_lehmer64_state *= UINT64_C(0xda942042e4dd58b5);
31-
return uint64_t(g_lehmer64_state >> 64);
34+
fast_float::value128 v = fast_float::full_multiplication(g_lehmer64_state.low,UINT64_C(0xda942042e4dd58b5));
35+
v.high += g_lehmer64_state.high * UINT64_C(0xda942042e4dd58b5);
36+
g_lehmer64_state = v;
37+
return v.high;
3238
}
3339

3440
size_t errors;

tests/random_string.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ class RandomEngine {
1111
// Inspired from
1212
// https://github.com/lemire/testingRNG/blob/master/source/wyhash.h
1313
wyhash64_x_ += UINT64_C(0x60bee2bee120fc15);
14-
__uint128_t tmp;
15-
tmp = (__uint128_t)wyhash64_x_ * UINT64_C(0xa3b195354a39b70d);
16-
uint64_t m1 = (tmp >> 64) ^ tmp;
17-
tmp = (__uint128_t)m1 * UINT64_C(0x1b03738712fad5c9);
18-
uint64_t m2 = (tmp >> 64) ^ tmp;
14+
fast_float::value128 tmp = fast_float::full_multiplication(wyhash64_x_, UINT64_C(0xa3b195354a39b70d));
15+
uint64_t m1 = (tmp.high) ^ tmp.low;
16+
tmp = fast_float::full_multiplication(m1, UINT64_C(0x1b03738712fad5c9));
17+
uint64_t m2 = (tmp.high) ^ tmp.low;
1918
return m2;
2019
}
2120
bool next_bool() { return (next() & 1) == 1; }
@@ -31,17 +30,17 @@ class RandomEngine {
3130
}*/
3231
int s = max - min + 1;
3332
uint64_t x = next();
34-
__uint128_t m = (__uint128_t)x * (__uint128_t)s;
35-
uint64_t l = (uint64_t)m;
33+
fast_float::value128 m = fast_float::full_multiplication(x, s);
34+
uint64_t l = m.low;
3635
if (l < s) {
3736
uint64_t t = -s % s;
3837
while (l < t) {
3938
x = next();
40-
m = (__uint128_t)x * (__uint128_t)s;
41-
l = (uint64_t)m;
39+
m = fast_float::full_multiplication(x, s);
40+
l = m.low;
4241
}
4342
}
44-
return (m >> 64) + min;
43+
return (m.high) + min;
4544
}
4645
int next_digit() { return next_ranged_int(0, 9); }
4746

@@ -113,7 +112,7 @@ std::pair<float, bool> strtof_from_string(char *st) {
113112
#endif
114113
if (st == pr) {
115114
std::cerr << "strtof_l could not parse '" << st << std::endl;
116-
return std::make_pair(0, false);
115+
return std::make_pair(0.0f, false);
117116
}
118117
return std::make_pair(d, true);
119118
}

tests/test.cpp

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)