Skip to content

Commit f44b682

Browse files
Merge pull request #709 from nipunG314/master
Add NBL_FP64_LITERAL macro
2 parents fcb891a + 283a8e7 commit f44b682

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/nbl/builtin/hlsl/limits.hlsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <nbl/builtin/hlsl/type_traits.hlsl>
88
#include <nbl/builtin/hlsl/bit.hlsl>
9+
#include <nbl/builtin/hlsl/macros.h>
910

1011
// C++ headers
1112
#ifndef __HLSL_VERSION
@@ -127,7 +128,7 @@ struct num_base : type_identity<T>
127128
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_decimal_exponent = 4*S16 + 30*S32 + 232*S64;
128129

129130
NBL_CONSTEXPR_STATIC_INLINE int32_t float_exponent_bits = 8 * size - float_digits - 1;
130-
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_exponent = 1l << float_exponent_bits;
131+
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_exponent = 1 << float_exponent_bits;
131132
NBL_CONSTEXPR_STATIC_INLINE int32_t float_min_exponent = 3 - float_max_exponent;
132133
NBL_CONSTEXPR_STATIC_INLINE bool is_bool = is_same<T, bool>::value;
133134

@@ -235,9 +236,9 @@ struct num_traits<float32_t> : num_base<float32_t>
235236
template<>
236237
struct num_traits<float64_t> : num_base<float64_t>
237238
{
238-
NBL_CONSTEXPR_STATIC_INLINE float64_t max = 1.7976931348623158e+308;
239-
NBL_CONSTEXPR_STATIC_INLINE float64_t min = 2.2250738585072014e-308;
240-
NBL_CONSTEXPR_STATIC_INLINE float64_t denorm_min = 4.9406564584124654e-324;
239+
NBL_CONSTEXPR_STATIC_INLINE float64_t max = NBL_FP64_LITERAL(1.7976931348623158e+308);
240+
NBL_CONSTEXPR_STATIC_INLINE float64_t min = NBL_FP64_LITERAL(2.2250738585072014e-308);
241+
NBL_CONSTEXPR_STATIC_INLINE float64_t denorm_min = NBL_FP64_LITERAL(4.9406564584124654e-324);
241242
NBL_CONSTEXPR_STATIC_INLINE uint64_t quiet_NaN = 0x7FF8000000000000ull;
242243
NBL_CONSTEXPR_STATIC_INLINE uint64_t signaling_NaN = 0x7FF0000000000001ull;
243244
NBL_CONSTEXPR_STATIC_INLINE uint64_t infinity = 0x7FF0000000000000ull;

include/nbl/builtin/hlsl/macros.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
}
1818
#endif
1919

20+
#ifdef __HLSL_VERSION // cause DXC is insane
21+
#define NBL_FP64_LITERAL(LIT) LIT##l
22+
#else // and nobody except GCC supports C++23 `f64` suffix on float literals
23+
#define NBL_FP64_LITERAL(LIT) LIT
24+
#endif
25+
2026
// basics
2127
#define NBL_EVAL(...) __VA_ARGS__
2228
#define NBL_CONCAT_IMPL2(X,Y) X ## Y
@@ -159,4 +165,4 @@
159165

160166
#define NBL_FOREACH(WHAT, ... ) NBL_EVAL(NBL_CONCATENATE(NBL_FOREACH_,NBL_VA_ARGS_COUNT(__VA_ARGS__))(WHAT, __VA_ARGS__))
161167

162-
#endif
168+
#endif

0 commit comments

Comments
 (0)