Skip to content

Commit

Permalink
bug fix on blockbinary conversion to ieee-754
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Nov 13, 2024
1 parent 59eedcf commit da74726
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 3 additions & 4 deletions include/universal/internal/blockbinary/blockbinary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,11 @@ class blockbinary {
Real to_native() const {
blockbinary tmp(*this);
if (isneg()) tmp.twosComplement();
Real v{ 1.0 }, base{ 1.0 };
for (unsigned i = 0; i < nbits - 1; ++i) {
if (tmp.test(i)) v *= base;
Real v{ 0.0 }, base{ 1.0 };
for (unsigned i = 0; i < nbits; ++i) {
if (tmp.test(i)) v += base;
base *= 2.0;
}

return (isneg() ? -v : v);
}
// determine the rounding mode: result needs to be rounded up if true
Expand Down
5 changes: 3 additions & 2 deletions static/rational/conversion/assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ try {

#if MANUAL_TESTING

rb8 a,b;
rb64 a,b;
a.set(0x02, 0x0A);
std::cout << to_binary(a) << '\n';
double da = double(a);
b = da;
std::cout << to_binary(da) << " : " << da << '\n';
std::cout << a << '\n';
std::cout << b << '\n';

return 0;
Ranges(1.0f);

// manual exhaustive test
Expand Down

0 comments on commit da74726

Please sign in to comment.