Skip to content

Commit

Permalink
Update code to use the support namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinzii committed Apr 9, 2024
1 parent d389200 commit e689c4c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions include/ccmath/math/fmanip/ldexp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,48 @@ namespace ccm
inline constexpr T ldexp(T x, int32_t powerOf2) noexcept
{
if (!ccm::isfinite(x)) { return x; }
int32_t oldexp = ccm::helpers::get_exponent_of_floating_point<T>(x);
int32_t oldexp = ccm::support::get_exponent_of_floating_point<T>(x);

// if the mantissa is 0 and the original exponent is 0
if ((oldexp == 0) && ((ccm::helpers::bit_cast<ccm::helpers::float_bits_t<T>>(x) &
ccm::helpers::floating_point_traits<T>::normal_mantissa_mask) == 0))
if ((oldexp == 0) && ((ccm::support::bit_cast<ccm::support::float_bits_t<T>>(x) &
ccm::support::floating_point_traits<T>::normal_mantissa_mask) == 0))
{
return x;
}

if (powerOf2 > ccm::helpers::floating_point_traits<T>::maximum_binary_exponent)
if (powerOf2 > ccm::support::floating_point_traits<T>::maximum_binary_exponent)
{
// error == hugeval
return std::numeric_limits<T>::infinity();
}
// the reference source says -2 * exp_max
else if (powerOf2 < ccm::helpers::floating_point_traits<T>::minimum_binary_exponent)
else if (powerOf2 < ccm::support::floating_point_traits<T>::minimum_binary_exponent)
{
// error == range
return 0;
}
// normalizes an abnormal floating point
if (oldexp == 0)
{
x *= ccm::helpers::floating_point_traits<T>::normalize_factor;
x *= ccm::support::floating_point_traits<T>::normalize_factor;
powerOf2 = -sizeof(T) * 8; //8 is bits in a byte
oldexp = ccm::helpers::get_exponent_of_floating_point<T>(x);
oldexp = ccm::support::get_exponent_of_floating_point<T>(x);
}

powerOf2 = oldexp + powerOf2;
if (powerOf2 >= ccm::helpers::floating_point_traits<T>::maximum_binary_exponent)
if (powerOf2 >= ccm::support::floating_point_traits<T>::maximum_binary_exponent)
{
// overflow
return std::numeric_limits<T>::infinity();
}
if (powerOf2 > 0)
{
return ccm::helpers::set_exponent_of_floating_point<T>(x, powerOf2);
return ccm::support::set_exponent_of_floating_point<T>(x, powerOf2);
}
// denormal, or underflow
powerOf2 += sizeof(T) * 8; //8 is bits in a byte
x = ccm::helpers::set_exponent_of_floating_point<T>(x, powerOf2);
x /= ccm::helpers::floating_point_traits<T>::normalize_factor;
x = ccm::support::set_exponent_of_floating_point<T>(x, powerOf2);
x /= ccm::support::floating_point_traits<T>::normalize_factor;
if (x == static_cast<T>(0))
{
// underflow report
Expand Down

0 comments on commit e689c4c

Please sign in to comment.