Skip to content

Commit 4c47bc0

Browse files
committed
add tests and minor reformat
1 parent 8687926 commit 4c47bc0

File tree

6 files changed

+70
-78
lines changed

6 files changed

+70
-78
lines changed

include/gcem.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ namespace gcem
3030
#include "gcem_incl/is_inf.hpp"
3131
#include "gcem_incl/is_nan.hpp"
3232
#include "gcem_incl/is_finite.hpp"
33+
34+
#include "gcem_incl/signbit.hpp"
35+
#include "gcem_incl/copysign.hpp"
36+
#include "gcem_incl/neg_zero.hpp"
37+
#include "gcem_incl/sgn.hpp"
3338

3439
#include "gcem_incl/abs.hpp"
3540
#include "gcem_incl/ceil.hpp"
@@ -42,11 +47,6 @@ namespace gcem
4247
#include "gcem_incl/sqrt.hpp"
4348
#include "gcem_incl/inv_sqrt.hpp"
4449

45-
#include "gcem_incl/signbit.hpp"
46-
#include "gcem_incl/copysign.hpp"
47-
#include "gcem_incl/neg_zero.hpp"
48-
#include "gcem_incl/sgn.hpp"
49-
5050
#include "gcem_incl/find_exponent.hpp"
5151
#include "gcem_incl/find_fraction.hpp"
5252
#include "gcem_incl/find_whole.hpp"

include/gcem_incl/ceil.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ float
5757
ceil_check_internal<float>(const float x)
5858
noexcept
5959
{
60-
//threshold = 8388608.f;
61-
62-
return (
63-
(abs(x) >= 8388608.f) ? \
64-
x : \
65-
ceil_int(x, float(static_cast<int>(x))) );
60+
return( abs(x) >= 8388608.f ? \
61+
// if
62+
x : \
63+
// else
64+
ceil_int(x, float(static_cast<int>(x))) );
6665
}
6766

6867
template<>
@@ -71,12 +70,11 @@ double
7170
ceil_check_internal<double>(const double x)
7271
noexcept
7372
{
74-
//threshold = 4503599627370496.;
75-
76-
return (
77-
(abs(x) >= 4503599627370496.) ? \
78-
x : \
79-
ceil_int(x, double(static_cast<llint_t>(x))) );
73+
return( abs(x) >= 4503599627370496. ? \
74+
// if
75+
x : \
76+
// else
77+
ceil_int(x, double(static_cast<llint_t>(x))) );
8078
}
8179

8280
template<>
@@ -85,12 +83,11 @@ long double
8583
ceil_check_internal<long double>(const long double x)
8684
noexcept
8785
{
88-
//threshold = 9223372036854775808.l;
89-
90-
return (
91-
(abs(x) >= 9223372036854775808.l) ? \
92-
x : \
93-
ceil_int(x, ((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l)) );
86+
return( abs(x) >= 9223372036854775808.l ? \
87+
// if
88+
x : \
89+
// else
90+
ceil_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
9491
}
9592

9693
template<typename T>

include/gcem_incl/floor.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ float
5757
floor_check_internal<float>(const float x)
5858
noexcept
5959
{
60-
//threshold = 8388608.f;
61-
62-
return (
63-
(abs(x) >= 8388608.f) ? \
64-
x : \
65-
floor_int(x, float(static_cast<int>(x))) );
60+
return( abs(x) >= 8388608.f ? \
61+
// if
62+
x : \
63+
// else
64+
floor_int(x, float(static_cast<int>(x))) );
6665
}
6766

6867
template<>
@@ -71,12 +70,11 @@ double
7170
floor_check_internal<double>(const double x)
7271
noexcept
7372
{
74-
//threshold = 4503599627370496.;
75-
76-
return (
77-
(abs(x) >= 4503599627370496.) ? \
78-
x : \
79-
floor_int(x, double(static_cast<llint_t>(x))) );
73+
return( abs(x) >= 4503599627370496. ? \
74+
// if
75+
x : \
76+
// else
77+
floor_int(x, double(static_cast<llint_t>(x))) );
8078
}
8179

8280
template<>
@@ -85,12 +83,11 @@ long double
8583
floor_check_internal<long double>(const long double x)
8684
noexcept
8785
{
88-
//threshold = 9223372036854775808.l;
89-
90-
return (
91-
(abs(x) >= 9223372036854775808.l) ? \
92-
x : \
93-
floor_int(x, ((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l)) );
86+
return( abs(x) >= 9223372036854775808.l ? \
87+
// if
88+
x : \
89+
// else
90+
floor_int(x, ((long double)static_cast<ullint_t>(abs(x))) * sgn(x)) );
9491
}
9592

9693
template<typename T>

include/gcem_incl/round.hpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ float
5252
round_check_internal<float>(const float x)
5353
noexcept
5454
{
55-
//threshold = 8388608.f;
56-
57-
return (
58-
(abs(x) >= 8388608.f) ? \
59-
x : \
60-
round_int(x) );
55+
return( abs(x) >= 8388608.f ? \
56+
// if
57+
x : \
58+
//else
59+
round_int(x) );
6160
}
6261

6362
template<>
@@ -66,12 +65,11 @@ double
6665
round_check_internal<double>(const double x)
6766
noexcept
6867
{
69-
//threshold = 4503599627370496.;
70-
71-
return (
72-
(abs(x) >= 4503599627370496.) ? \
73-
x : \
74-
round_int(x) );
68+
return( abs(x) >= 4503599627370496. ? \
69+
// if
70+
x : \
71+
// else
72+
round_int(x) );
7573
}
7674

7775
template<>
@@ -80,12 +78,11 @@ long double
8078
round_check_internal<long double>(const long double x)
8179
noexcept
8280
{
83-
//threshold = 9223372036854775808.l;
84-
85-
return (
86-
(abs(x) >= 9223372036854775808.l) ? \
87-
x : \
88-
round_int(x) );
81+
return( abs(x) >= 9223372036854775808.l ? \
82+
// if
83+
x : \
84+
// else
85+
round_int(x) );
8986
}
9087

9188
template<typename T>
@@ -104,7 +101,7 @@ noexcept
104101
GCLIM<T>::min() > abs(x) ? \
105102
x :
106103
// else
107-
sgn(x) * round_int(abs(x)) );
104+
sgn(x) * round_check_internal(abs(x)) );
108105
}
109106

110107
}

include/gcem_incl/trunc.hpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ float
4848
trunc_check_internal<float>(const float x)
4949
noexcept
5050
{
51-
//threshold = 8388608.f;
52-
53-
return (
54-
(abs(x) >= 8388608.f) ? \
55-
x : \
56-
trunc_int(x) );
51+
return( abs(x) >= 8388608.f ? \
52+
// if
53+
x : \
54+
// else
55+
trunc_int(x) );
5756
}
5857

5958
template<>
@@ -62,12 +61,11 @@ double
6261
trunc_check_internal<double>(const double x)
6362
noexcept
6463
{
65-
//threshold = 4503599627370496.;
66-
67-
return (
68-
(abs(x) >= 4503599627370496.) ? \
69-
x : \
70-
trunc_int(x) );
64+
return( abs(x) >= 4503599627370496. ? \
65+
// if
66+
x : \
67+
// else
68+
trunc_int(x) );
7169
}
7270

7371
template<>
@@ -76,12 +74,11 @@ long double
7674
trunc_check_internal<long double>(const long double x)
7775
noexcept
7876
{
79-
//threshold = 9223372036854775808.l;
80-
81-
return (
82-
(abs(x) >= 9223372036854775808.l) ? \
83-
x : \
84-
((long double)static_cast<ullint_t>(abs(x))) * ((x < 0) ? -1.l : 1.l) );
77+
return( abs(x) >= 9223372036854775808.l ? \
78+
// if
79+
x : \
80+
// else
81+
((long double)static_cast<ullint_t>(abs(x))) * sgn(x) );
8582
}
8683

8784
template<typename T>

tests/rounding.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main()
3939
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.7);
4040
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -5.0);
4141
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 42e32);
42+
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -42e32);
4243

4344
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits<float>::max());
4445
GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -std::numeric_limits<long double>::infinity());
@@ -57,6 +58,7 @@ int main()
5758
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.7);
5859
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -5.0);
5960
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 42e32);
61+
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -42e32);
6062

6163
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits<float>::max());
6264
GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -std::numeric_limits<long double>::infinity());
@@ -75,6 +77,7 @@ int main()
7577
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.7);
7678
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -5.0);
7779
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 42e32);
80+
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -42e32);
7881

7982
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits<float>::max());
8083
GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -std::numeric_limits<long double>::infinity());
@@ -94,6 +97,7 @@ int main()
9497
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.7);
9598
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -5.0);
9699
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 42e32);
100+
GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -42e32);
97101

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

0 commit comments

Comments
 (0)