Skip to content

Commit

Permalink
fix another bug in int128_no_intrinstic
Browse files Browse the repository at this point in the history
  • Loading branch information
guuzaa committed Mar 24, 2024
1 parent c9d9738 commit 549591c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/include/int128_no_intrinstic.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ inline int128::operator float() const {
//
// Also check to make sure we don't negate Int128Min()
return hi_ < 0 && *this != MIN ? -static_cast<float>(-*this)
: static_cast<float>(lo_) + std::ldexp(static_cast<float>(hi_), 64);
: static_cast<float>(lo_) + std::ldexp(static_cast<float>(hi_), 64);
}

inline int128::operator double() const {
// See comment in int128::operator float() above.
return hi_ < 0 && *this != MIN ? -static_cast<double>(-*this)
: static_cast<double>(lo_) + std::ldexp(static_cast<double>(hi_), 64);
: static_cast<double>(lo_) + std::ldexp(static_cast<double>(hi_), 64);
}

inline int128::operator long double() const {
// See comment in int128::operator float() above.
return hi_ < 0 && *this != MIN ? -static_cast<long double>(-*this)
: static_cast<long double>(lo_) + std::ldexp(static_cast<long double>(hi_), 64);
: static_cast<long double>(lo_) + std::ldexp(static_cast<long double>(hi_), 64);
}

// Comparison operators
Expand Down
2 changes: 1 addition & 1 deletion src/numbers/int128.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ int128 make_int128_from_float(T v) {
assert(std::isfinite(v) && (std::numeric_limits<T>::max_exponent <= 127 ||
(v >= -std::ldexp(static_cast<T>(1), 127) && v < std::ldexp(static_cast<T>(1), 127))));
uint128 result = v < 0 ? -make_uint128_from_float(-v) : make_uint128_from_float(v);
return make_int128(int128_internal::BitCastToSigned(uint128_high64(result), uint128_low64(result)));
return make_int128(int128_internal::BitCastToSigned(uint128_high64(result)), uint128_low64(result));
}

} // namespace
Expand Down

0 comments on commit 549591c

Please sign in to comment.