Skip to content

Commit

Permalink
add tests and minor reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
kthohr committed Jul 31, 2022
1 parent 8687926 commit 4c47bc0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 78 deletions.
10 changes: 5 additions & 5 deletions include/gcem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace gcem
#include "gcem_incl/is_inf.hpp"
#include "gcem_incl/is_nan.hpp"
#include "gcem_incl/is_finite.hpp"

#include "gcem_incl/signbit.hpp"
#include "gcem_incl/copysign.hpp"
#include "gcem_incl/neg_zero.hpp"
#include "gcem_incl/sgn.hpp"

#include "gcem_incl/abs.hpp"
#include "gcem_incl/ceil.hpp"
Expand All @@ -42,11 +47,6 @@ namespace gcem
#include "gcem_incl/sqrt.hpp"
#include "gcem_incl/inv_sqrt.hpp"

#include "gcem_incl/signbit.hpp"
#include "gcem_incl/copysign.hpp"
#include "gcem_incl/neg_zero.hpp"
#include "gcem_incl/sgn.hpp"

#include "gcem_incl/find_exponent.hpp"
#include "gcem_incl/find_fraction.hpp"
#include "gcem_incl/find_whole.hpp"
Expand Down
33 changes: 15 additions & 18 deletions include/gcem_incl/ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ float
ceil_check_internal<float>(const float x)
noexcept
{
//threshold = 8388608.f;

return (
(abs(x) >= 8388608.f) ? \
x : \
ceil_int(x, float(static_cast<int>(x))) );
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
ceil_int(x, float(static_cast<int>(x))) );
}

template<>
Expand All @@ -71,12 +70,11 @@ double
ceil_check_internal<double>(const double x)
noexcept
{
//threshold = 4503599627370496.;

return (
(abs(x) >= 4503599627370496.) ? \
x : \
ceil_int(x, double(static_cast<llint_t>(x))) );
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
ceil_int(x, double(static_cast<llint_t>(x))) );
}

template<>
Expand All @@ -85,12 +83,11 @@ long double
ceil_check_internal<long double>(const long double x)
noexcept
{
//threshold = 9223372036854775808.l;

return (
(abs(x) >= 9223372036854775808.l) ? \
x : \
ceil_int(x, ((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l)) );
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
ceil_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
}

template<typename T>
Expand Down
33 changes: 15 additions & 18 deletions include/gcem_incl/floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ float
floor_check_internal<float>(const float x)
noexcept
{
//threshold = 8388608.f;

return (
(abs(x) >= 8388608.f) ? \
x : \
floor_int(x, float(static_cast<int>(x))) );
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
floor_int(x, float(static_cast<int>(x))) );
}

template<>
Expand All @@ -71,12 +70,11 @@ double
floor_check_internal<double>(const double x)
noexcept
{
//threshold = 4503599627370496.;

return (
(abs(x) >= 4503599627370496.) ? \
x : \
floor_int(x, double(static_cast<llint_t>(x))) );
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
floor_int(x, double(static_cast<llint_t>(x))) );
}

template<>
Expand All @@ -85,12 +83,11 @@ long double
floor_check_internal<long double>(const long double x)
noexcept
{
//threshold = 9223372036854775808.l;

return (
(abs(x) >= 9223372036854775808.l) ? \
x : \
floor_int(x, ((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l)) );
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
floor_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
}

template<typename T>
Expand Down
35 changes: 16 additions & 19 deletions include/gcem_incl/round.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ float
round_check_internal<float>(const float x)
noexcept
{
//threshold = 8388608.f;

return (
(abs(x) >= 8388608.f) ? \
x : \
round_int(x) );
return( abs(x) >= 8388608.f ? \
// if
x : \
//else
round_int(x) );
}

template<>
Expand All @@ -66,12 +65,11 @@ double
round_check_internal<double>(const double x)
noexcept
{
//threshold = 4503599627370496.;

return (
(abs(x) >= 4503599627370496.) ? \
x : \
round_int(x) );
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
round_int(x) );
}

template<>
Expand All @@ -80,12 +78,11 @@ long double
round_check_internal<long double>(const long double x)
noexcept
{
//threshold = 9223372036854775808.l;

return (
(abs(x) >= 9223372036854775808.l) ? \
x : \
round_int(x) );
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
round_int(x) );
}

template<typename T>
Expand All @@ -104,7 +101,7 @@ noexcept
GCLIM<T>::min() > abs(x) ? \
x :
// else
sgn(x) * round_int(abs(x)) );
sgn(x) * round_check_internal(abs(x)) );
}

}
Expand Down
33 changes: 15 additions & 18 deletions include/gcem_incl/trunc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ float
trunc_check_internal<float>(const float x)
noexcept
{
//threshold = 8388608.f;

return (
(abs(x) >= 8388608.f) ? \
x : \
trunc_int(x) );
return( abs(x) >= 8388608.f ? \
// if
x : \
// else
trunc_int(x) );
}

template<>
Expand All @@ -62,12 +61,11 @@ double
trunc_check_internal<double>(const double x)
noexcept
{
//threshold = 4503599627370496.;

return (
(abs(x) >= 4503599627370496.) ? \
x : \
trunc_int(x) );
return( abs(x) >= 4503599627370496. ? \
// if
x : \
// else
trunc_int(x) );
}

template<>
Expand All @@ -76,12 +74,11 @@ long double
trunc_check_internal<long double>(const long double x)
noexcept
{
//threshold = 9223372036854775808.l;

return (
(abs(x) >= 9223372036854775808.l) ? \
x : \
((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l) );
return( abs(x) >= 9223372036854775808.l ? \
// if
x : \
// else
((long double)static_cast<ullint_t>(abs(x))) * sgn(x) );
}

template<typename T>
Expand Down
4 changes: 4 additions & 0 deletions tests/rounding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int main()
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.7);
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -5.0);
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 42e32);
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -42e32);

GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits<float>::max());
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -std::numeric_limits<long double>::infinity());
Expand All @@ -57,6 +58,7 @@ int main()
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.7);
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -5.0);
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 42e32);
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -42e32);

GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits<float>::max());
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -std::numeric_limits<long double>::infinity());
Expand All @@ -75,6 +77,7 @@ int main()
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.7);
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -5.0);
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 42e32);
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -42e32);

GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits<float>::max());
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -std::numeric_limits<long double>::infinity());
Expand All @@ -94,6 +97,7 @@ int main()
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.7);
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -5.0);
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 42e32);
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -42e32);

GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits<float>::max());
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -std::numeric_limits<long double>::infinity());
Expand Down

0 comments on commit 4c47bc0

Please sign in to comment.