Skip to content

Commit

Permalink
bug fix: API on extractFields was inconsistent wrt long double
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Nov 2, 2024
1 parent 90edaaa commit e4cf3cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/universal/native/extract_fields.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace sw { namespace universal {
#include <bit> // C++20 bit_cast

// specialization to extract fields from a float
inline BIT_CAST_CONSTEXPR void extractFields(float value, bool& s, uint32_t& rawExponentBits, uint32_t& rawFractionBits, uint32_t& bits) noexcept {
inline BIT_CAST_CONSTEXPR void extractFields(float value, bool& s, uint64_t& rawExponentBits, uint64_t& rawFractionBits, uint64_t& bits) noexcept {
uint32_t bc = std::bit_cast<uint32_t, float>(value);
s = (ieee754_parameter<float>::smask & bc);
rawExponentBits = (ieee754_parameter<float>::emask & bc) >> ieee754_parameter<float>::fbits;
Expand Down
16 changes: 8 additions & 8 deletions static/native/float/bit_manipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ namespace sw { namespace universal {
int nrOfFailedTests = 0;

#if defined(UNIVERSAL_ARCH_X86_64)
std::cout << "Architecture is x86_64\n";
std::cout << "Architecture is x86_64\n";
#elif defined(UNIVERSAL_ARCH_ARM)
std::cout << "Architecture is ARM\n";
std::cout << "Architecture is ARM\n";
#elif defined(UNIVERSAL_ARCH_RISCV)
std::cout << "Architecture is RISC-V\n";
#else
std::cout << "Architecture is unknown\n";
std::cout << "Architecture is unknown\n";
#endif
bool sign{ false };
uint64_t rawExponent{ 0 };
int exponent{ 0 };
uint64_t rawFraction{ 0 };
uint64_t bits{ 0 };

Real a;
a = 1.0;
std::cout << to_binary(a) << " : " << a << '\n';
ReportValue(a);
Real a{ 1.0 };
std::cout << "IEEE-754 value : " << to_binary(a) << " : " << a << '\n';

extractFields(a, sign, rawExponent, rawFraction, bits);
exponent = static_cast<int>(rawExponent) - ieee754_parameter<Real>::bias;
Expand All @@ -52,7 +52,7 @@ std::cout << "Architecture is unknown\n";
std::cout << "unbiased exponent : " << exponent << '\n';
if (sign != false || exponent != 0 || rawFraction != 0) {
++nrOfFailedTests;
if (reportTestCases) std::cerr << "fp components: " << (sign ? '1' : '0') << " exp: " << exponent << " frac: " << to_binary(rawFraction, fbits, true) << '\n';
if (reportTestCases) std::cerr << "fp components: " << (sign ? '1' : '0') << " exp: " << exponent << " frac: " << to_binary(rawFraction, true, fbits) << '\n';
}

return nrOfFailedTests;
Expand Down
3 changes: 3 additions & 0 deletions static/native/float/fractionviz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ try {
std::cout << "double precision float : " << to_triple(d) << '\n';
std::cout << "long double precision float: " << to_triple(ld) << '\n';


#if LONG_DOUBLE_SUPPORT
ReportFields(ld);
#endif

// special values
f = float(nan("NaN"));
Expand Down

0 comments on commit e4cf3cd

Please sign in to comment.