mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Remove the medium_prec_bin type
It's obsolete now that we have an Eisel algorithm implementation. Binary size, before: 29416 gen/lib/c/clang-5.0-dynamic/wuffs-base-f64conv.lo 29688 gen/lib/c/clang-5.0-static/wuffs-base-f64conv.o 31792 gen/lib/c/gcc-dynamic/wuffs-base-f64conv.lo 31792 gen/lib/c/gcc-static/wuffs-base-f64conv.o After: 28744 gen/lib/c/clang-5.0-dynamic/wuffs-base-f64conv.lo 28968 gen/lib/c/clang-5.0-static/wuffs-base-f64conv.o 31176 gen/lib/c/gcc-dynamic/wuffs-base-f64conv.lo 31176 gen/lib/c/gcc-static/wuffs-base-f64conv.o Processing citylots.json from github.com/zemirco/sf-city-lots-json $ g++ -O3 script/process-json-numbers.c $ time ./a.out -parse-number-f64 < citylots.json Before/After: real 0m1.031s real 0m0.975s $ time ./a.out < citylots.json Before/After: real 0m0.807s real 0m0.729s
This commit is contained in:
1 parent
86093c8194
commit
832edf7227
4 files changed
+110
-867
No files matched your search
@@ -419,133 +419,6 @@ test_wuffs_strconv_hpd_shift() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_strconv_mpb_assign_from_hpd() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
const char* str;
|
||||
int32_t decimal_point;
|
||||
uint64_t want_mantissa;
|
||||
int32_t want_exp2;
|
||||
double want_f64;
|
||||
} test_cases[] = {
|
||||
|
||||
// (0x818995CE7AA0E1B2 * (2 ** -1136)) is roughly 1e-323
|
||||
//
|
||||
// 1e-323 is roughly twice 4.94066e-324, the minimum subnormal positive
|
||||
// double-precision floating point number.
|
||||
{.str = "1",
|
||||
.decimal_point = -322,
|
||||
.want_mantissa = 0x818995CE7AA0E1B2,
|
||||
.want_exp2 = -1136,
|
||||
.want_f64 = 1e-323},
|
||||
|
||||
// (0xD1B71758E219652C * (2 ** -77)) is roughly .0001
|
||||
{.str = "1",
|
||||
.decimal_point = -3,
|
||||
.want_mantissa = 0xD1B71758E219652C,
|
||||
.want_exp2 = -77,
|
||||
.want_f64 = .0001},
|
||||
|
||||
// (0xCCCCCCCCCCCCCCCE * (2 ** -67)) is roughly .1
|
||||
{.str = "1",
|
||||
.decimal_point = +0,
|
||||
.want_mantissa = 0xCCCCCCCCCCCCCCCC,
|
||||
.want_exp2 = -67,
|
||||
.want_f64 = .1},
|
||||
|
||||
// (0x8000000000000000 * (2 ** -63)) is 1.
|
||||
{.str = "1",
|
||||
.decimal_point = +1,
|
||||
.want_mantissa = 0x8000000000000000,
|
||||
.want_exp2 = -63,
|
||||
.want_f64 = 1},
|
||||
|
||||
// (0xA000000000000000 * (2 ** -60)) is 10.
|
||||
{.str = "1",
|
||||
.decimal_point = +2,
|
||||
.want_mantissa = 0xA000000000000000,
|
||||
.want_exp2 = -60,
|
||||
.want_f64 = 10},
|
||||
|
||||
// (0xC9F2C9CD04674EDE * (2 ** +36)) is roughly 1e30.
|
||||
{.str = "1",
|
||||
.decimal_point = +31,
|
||||
.want_mantissa = 0xC9F2C9CD04674EDE,
|
||||
.want_exp2 = +36,
|
||||
.want_f64 = 1e30},
|
||||
|
||||
// (0xDE81E40A034BCF50 * (2 ** +966)) is roughly 1e310.
|
||||
//
|
||||
// 1e310 is almost 50 times larger than DBL_MAX (roughly 1.8e308), so it
|
||||
// should be converted to +infinity.
|
||||
{.str = "1",
|
||||
.decimal_point = +311,
|
||||
.want_mantissa = 0xDE81E40A034BCF50,
|
||||
.want_exp2 = +966,
|
||||
.want_f64 = (1.0 / 0.0)},
|
||||
|
||||
// (0x9A40000000000000 * (2 ** -53)) is 1234.
|
||||
{.str = "1234",
|
||||
.decimal_point = +4,
|
||||
.want_mantissa = 0x9A40000000000000,
|
||||
.want_exp2 = -53,
|
||||
.want_f64 = 1234},
|
||||
|
||||
// (0xC90FCF80DC33721E * (2 ** -62)) is roughly 3.14159
|
||||
{.str = "314159",
|
||||
.decimal_point = +1,
|
||||
.want_mantissa = 0xC90FCF80DC33721E,
|
||||
.want_exp2 = -62,
|
||||
.want_f64 = 3.14159},
|
||||
};
|
||||
|
||||
int tc;
|
||||
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__private_implementation__high_prec_dec hpd;
|
||||
|
||||
// Initialize hpd.
|
||||
uint32_t i;
|
||||
for (i = 0; test_cases[tc].str[i]; i++) {
|
||||
hpd.digits[i] = test_cases[tc].str[i] - '0';
|
||||
}
|
||||
hpd.num_digits = i;
|
||||
hpd.decimal_point = test_cases[tc].decimal_point;
|
||||
hpd.negative = false;
|
||||
hpd.truncated = false;
|
||||
|
||||
static const bool skip_fast_path_for_tests = true;
|
||||
wuffs_base__private_implementation__medium_prec_bin mpb;
|
||||
wuffs_base__private_implementation__medium_prec_bin__parse_number_f64(
|
||||
&mpb, &hpd, skip_fast_path_for_tests);
|
||||
|
||||
uint64_t have_mantissa = mpb.mantissa;
|
||||
if (have_mantissa != test_cases[tc].want_mantissa) {
|
||||
RETURN_FAIL("%s@%d: mantissa: have 0x%" PRIX64 ", want 0x%" PRIX64,
|
||||
test_cases[tc].str, test_cases[tc].decimal_point,
|
||||
have_mantissa, test_cases[tc].want_mantissa);
|
||||
}
|
||||
|
||||
int32_t have_exp2 = mpb.exp2;
|
||||
if (have_exp2 != test_cases[tc].want_exp2) {
|
||||
RETURN_FAIL("%s@%d: exp2: have %" PRId32 ", want %" PRId32,
|
||||
test_cases[tc].str, test_cases[tc].decimal_point, have_exp2,
|
||||
test_cases[tc].want_exp2);
|
||||
}
|
||||
|
||||
double have_f64 =
|
||||
wuffs_base__private_implementation__medium_prec_bin__as_f64(&mpb,
|
||||
false);
|
||||
if (have_f64 != test_cases[tc].want_f64) {
|
||||
RETURN_FAIL("%s@%d: f64: have %g, want %g", test_cases[tc].str,
|
||||
test_cases[tc].decimal_point, have_f64,
|
||||
test_cases[tc].want_f64);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ----------------
|
||||
|
||||
const char* //
|
||||
@@ -3470,7 +3343,6 @@ proc g_tests[] = {
|
||||
test_wuffs_strconv_hexadecimal,
|
||||
test_wuffs_strconv_hpd_rounded_integer,
|
||||
test_wuffs_strconv_hpd_shift,
|
||||
test_wuffs_strconv_mpb_assign_from_hpd,
|
||||
test_wuffs_strconv_parse_number_f64,
|
||||
test_wuffs_strconv_parse_number_i64,
|
||||
test_wuffs_strconv_parse_number_u64,
|
||||
|
||||
Reference in new issue
Block a user