@@ -32,22 +32,9 @@ static const double PI_VAL =
3232 3.1415926535897932384626433832795028841971693993751058209749445923078164 ;
3333
3434// Conversion to half adapted from Random123
35- #define HALF_FACTOR ((1 .0f ) / (std::numeric_limits<ushort>::max() + (1 .0f )))
36- #define HALF_HALF_FACTOR ((0 .5f ) * HALF_FACTOR)
37-
38- // Conversion to half adapted from Random123
39- #define SIGNED_HALF_FACTOR \
40- ((1 .0f ) / (std::numeric_limits<short >::max() + (1 .0f )))
41- #define SIGNED_HALF_HALF_FACTOR ((0 .5f ) * SIGNED_HALF_FACTOR)
42-
43- #define DBL_FACTOR \
44- ((1.0 ) / (std::numeric_limits<unsigned long long >::max() + (1.0 )))
45- #define HALF_DBL_FACTOR ((0.5 ) * DBL_FACTOR)
46-
47- // Conversion to floats adapted from Random123
48- #define SIGNED_DBL_FACTOR \
49- ((1.0 ) / (std::numeric_limits<long long >::max() + (1.0 )))
50- #define SIGNED_HALF_DBL_FACTOR ((0.5 ) * SIGNED_DBL_FACTOR)
35+ constexpr float unsigned_half_factor =
36+ ((1 .0f ) / (std::numeric_limits<ushort>::max() + (1 .0f )));
37+ constexpr float unsigned_half_half_factor ((0 .5f ) * unsigned_half_factor);
5138
5239template <typename T>
5340T transform (uint *val, uint index);
@@ -85,14 +72,19 @@ static float getFloatNegative11(uint *val, uint index) {
8572// Generates rationals in [0, 1)
8673common::half getHalf01 (uint *val, uint index) {
8774 float v = val[index >> 1U ] >> (16U * (index & 1U )) & 0x0000ffff ;
88- return static_cast <common::half>(fmaf (v, HALF_FACTOR, HALF_HALF_FACTOR));
75+ return static_cast <common::half>(
76+ fmaf (v, unsigned_half_factor, unsigned_half_half_factor));
8977}
9078
9179// Generates rationals in (-1, 1]
9280static common::half getHalfNegative11 (uint *val, uint index) {
9381 float v = val[index >> 1U ] >> (16U * (index & 1U )) & 0x0000ffff ;
94- return static_cast <common::half>(
95- fmaf (v, SIGNED_HALF_FACTOR, SIGNED_HALF_HALF_FACTOR));
82+ // Conversion to half adapted from Random123
83+ constexpr float factor =
84+ ((1 .0f ) / (std::numeric_limits<short >::max () + (1 .0f )));
85+ constexpr float half_factor = ((0 .5f ) * factor);
86+
87+ return static_cast <common::half>(fmaf (v, factor, half_factor));
9688}
9789
9890// Generates rationals in [0, 1)
@@ -160,8 +152,8 @@ double transform<double>(uint *val, uint index) {
160152template <>
161153common::half transform<common::half>(uint *val, uint index) {
162154 float v = val[index >> 1U ] >> (16U * (index & 1U )) & 0x0000ffff ;
163- return static_cast <common::half>(1 . f -
164- fmaf (v, HALF_FACTOR, HALF_HALF_FACTOR ));
155+ return static_cast <common::half>(
156+ 1 . f - fmaf (v, unsigned_half_factor, unsigned_half_half_factor ));
165157}
166158
167159// Generates rationals in [-1, 1)
0 commit comments