Skip to content

Commit

Permalink
Weaken f80 assertions in test_float for non-x86 (rizinorg#4280)
Browse files Browse the repository at this point in the history
OpenBSD/sparc64 uses 128-bit floats as long double by default while our
tests seeminly assumed either 64-bit or 80-bit, both of which produce
different results than 128 here. Since 80-bit is x86-specific, we check
only the bits we know will be identical between other architectures.
  • Loading branch information
thestr4ng3r authored Feb 21, 2024
1 parent 1011553 commit 2a9f765
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/unit/test_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,23 @@ bool float_print_num(void) {
rz_float_free(f64);

RzFloat *f80 = rz_float_new_from_f80(13.0335l);
/* Need the check since ARM does not support 128-bit long doubles and Windows ignores it. */
#if __arm__ || __arm64__ || __WINDOWS__
mu_assert_streq_free(rz_float_as_hex_string(f80, true), "0x4002d089374bc6a7f000", "float80 hex value");
#else
// Need the check since 80-bit long double is an x86 speciality and MSVC ignores it.
#if (__i386__ || __x86_64__) && !__WINDOWS__
mu_assert_streq_free(rz_float_as_hex_string(f80, true), "0x4002d089374bc6a7ef9e", "float80 hex value");
#endif
#if __arm__ || __arm64__ || __WINDOWS__
mu_assert_streq_free(rz_float_as_string(f80), "+100000000000010|1101000010001001001101110100101111000110101001111111000000000000", "float80 bit value");
#else
mu_assert_streq_free(rz_float_as_string(f80), "+100000000000010|1101000010001001001101110100101111000110101001111110111110011110", "float80 bit value");
#else
char *str = rz_float_as_hex_string(f80, true);
if (str && strlen(str) == 22) {
// Mask away anything beyond 64-bit influence because it differs between sparc and arm for example.
memset(str + 18, 'x', 4);
}
mu_assert_streq_free(str, "0x4002d089374bc6a7xxxx", "float80 hex value");
str = rz_float_as_string(f80);
if (str && strlen(str) == 81) {
// Mask away anything beyond 64-bit influence because it differs between sparc and arm for example.
memset(str + 60, 'x', 81 - 60);
}
mu_assert_streq_free(str, "+100000000000010|1101000010001001001101110100101111000110101xxxxxxxxxxxxxxxxxxxxx", "float80 bit value");
#endif
mu_assert_streq_free(rz_float_as_dec_string(f80), "13.0335", "float80 numeric value");
rz_float_free(f80);
Expand Down

0 comments on commit 2a9f765

Please sign in to comment.