1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "../sys/platform.h"
7
8#include <limits>
9
10#define _USE_MATH_DEFINES
11#include <math.h> // using cmath causes issues under Windows
12#include <cfloat>
13#include <climits>
14
15namespace embree
16{
17 static MAYBE_UNUSED const float one_over_255 = 1.0f/255.0f;
18 static MAYBE_UNUSED const float min_rcp_input = 1E-18f; // for abs(x) >= min_rcp_input the newton raphson rcp calculation does not fail
19
20 /* we consider floating point numbers in that range as valid input numbers */
21 static MAYBE_UNUSED float FLT_LARGE = 1.844E18f;
22
23 struct TrueTy {
24 __forceinline operator bool( ) const { return true; }
25 };
26
27 const constexpr TrueTy True = TrueTy();
28
29 struct FalseTy {
30 __forceinline operator bool( ) const { return false; }
31 };
32
33 const constexpr FalseTy False = FalseTy();
34
35 struct ZeroTy
36 {
37 __forceinline operator double ( ) const { return 0; }
38 __forceinline operator float ( ) const { return 0; }
39 __forceinline operator long long( ) const { return 0; }
40 __forceinline operator unsigned long long( ) const { return 0; }
41 __forceinline operator long ( ) const { return 0; }
42 __forceinline operator unsigned long ( ) const { return 0; }
43 __forceinline operator int ( ) const { return 0; }
44 __forceinline operator unsigned int ( ) const { return 0; }
45 __forceinline operator short ( ) const { return 0; }
46 __forceinline operator unsigned short ( ) const { return 0; }
47 __forceinline operator char ( ) const { return 0; }
48 __forceinline operator unsigned char ( ) const { return 0; }
49 };
50
51 const constexpr ZeroTy zero = ZeroTy();
52
53 struct OneTy
54 {
55 __forceinline operator double ( ) const { return 1; }
56 __forceinline operator float ( ) const { return 1; }
57 __forceinline operator long long( ) const { return 1; }
58 __forceinline operator unsigned long long( ) const { return 1; }
59 __forceinline operator long ( ) const { return 1; }
60 __forceinline operator unsigned long ( ) const { return 1; }
61 __forceinline operator int ( ) const { return 1; }
62 __forceinline operator unsigned int ( ) const { return 1; }
63 __forceinline operator short ( ) const { return 1; }
64 __forceinline operator unsigned short ( ) const { return 1; }
65 __forceinline operator char ( ) const { return 1; }
66 __forceinline operator unsigned char ( ) const { return 1; }
67 };
68
69 const constexpr OneTy one = OneTy();
70
71 struct NegInfTy
72 {
73 __forceinline operator double ( ) const { return -std::numeric_limits<double>::infinity(); }
74 __forceinline operator float ( ) const { return -std::numeric_limits<float>::infinity(); }
75 __forceinline operator long long( ) const { return std::numeric_limits<long long>::min(); }
76 __forceinline operator unsigned long long( ) const { return std::numeric_limits<unsigned long long>::min(); }
77 __forceinline operator long ( ) const { return std::numeric_limits<long>::min(); }
78 __forceinline operator unsigned long ( ) const { return std::numeric_limits<unsigned long>::min(); }
79 __forceinline operator int ( ) const { return std::numeric_limits<int>::min(); }
80 __forceinline operator unsigned int ( ) const { return std::numeric_limits<unsigned int>::min(); }
81 __forceinline operator short ( ) const { return std::numeric_limits<short>::min(); }
82 __forceinline operator unsigned short ( ) const { return std::numeric_limits<unsigned short>::min(); }
83 __forceinline operator char ( ) const { return std::numeric_limits<char>::min(); }
84 __forceinline operator unsigned char ( ) const { return std::numeric_limits<unsigned char>::min(); }
85
86 };
87
88 const constexpr NegInfTy neg_inf = NegInfTy();
89
90 struct PosInfTy
91 {
92 __forceinline operator double ( ) const { return std::numeric_limits<double>::infinity(); }
93 __forceinline operator float ( ) const { return std::numeric_limits<float>::infinity(); }
94 __forceinline operator long long( ) const { return std::numeric_limits<long long>::max(); }
95 __forceinline operator unsigned long long( ) const { return std::numeric_limits<unsigned long long>::max(); }
96 __forceinline operator long ( ) const { return std::numeric_limits<long>::max(); }
97 __forceinline operator unsigned long ( ) const { return std::numeric_limits<unsigned long>::max(); }
98 __forceinline operator int ( ) const { return std::numeric_limits<int>::max(); }
99 __forceinline operator unsigned int ( ) const { return std::numeric_limits<unsigned int>::max(); }
100 __forceinline operator short ( ) const { return std::numeric_limits<short>::max(); }
101 __forceinline operator unsigned short ( ) const { return std::numeric_limits<unsigned short>::max(); }
102 __forceinline operator char ( ) const { return std::numeric_limits<char>::max(); }
103 __forceinline operator unsigned char ( ) const { return std::numeric_limits<unsigned char>::max(); }
104 };
105
106 const constexpr PosInfTy inf = PosInfTy();
107 const constexpr PosInfTy pos_inf = PosInfTy();
108
109 struct NaNTy
110 {
111 __forceinline operator double( ) const { return std::numeric_limits<double>::quiet_NaN(); }
112 __forceinline operator float ( ) const { return std::numeric_limits<float>::quiet_NaN(); }
113 };
114
115 const constexpr NaNTy nan = NaNTy();
116
117 struct UlpTy
118 {
119 __forceinline operator double( ) const { return std::numeric_limits<double>::epsilon(); }
120 __forceinline operator float ( ) const { return std::numeric_limits<float>::epsilon(); }
121 };
122
123 const constexpr UlpTy ulp = UlpTy();
124
125 struct PiTy
126 {
127 __forceinline operator double( ) const { return double(M_PI); }
128 __forceinline operator float ( ) const { return float(M_PI); }
129 };
130
131 const constexpr PiTy pi = PiTy();
132
133 struct OneOverPiTy
134 {
135 __forceinline operator double( ) const { return double(M_1_PI); }
136 __forceinline operator float ( ) const { return float(M_1_PI); }
137 };
138
139 const constexpr OneOverPiTy one_over_pi = OneOverPiTy();
140
141 struct TwoPiTy
142 {
143 __forceinline operator double( ) const { return double(2.0*M_PI); }
144 __forceinline operator float ( ) const { return float(2.0*M_PI); }
145 };
146
147 const constexpr TwoPiTy two_pi = TwoPiTy();
148
149 struct OneOverTwoPiTy
150 {
151 __forceinline operator double( ) const { return double(0.5*M_1_PI); }
152 __forceinline operator float ( ) const { return float(0.5*M_1_PI); }
153 };
154
155 const constexpr OneOverTwoPiTy one_over_two_pi = OneOverTwoPiTy();
156
157 struct FourPiTy
158 {
159 __forceinline operator double( ) const { return double(4.0*M_PI); }
160 __forceinline operator float ( ) const { return float(4.0*M_PI); }
161 };
162
163 const constexpr FourPiTy four_pi = FourPiTy();
164
165 struct OneOverFourPiTy
166 {
167 __forceinline operator double( ) const { return double(0.25*M_1_PI); }
168 __forceinline operator float ( ) const { return float(0.25*M_1_PI); }
169 };
170
171 const constexpr OneOverFourPiTy one_over_four_pi = OneOverFourPiTy();
172
173 struct StepTy {
174 __forceinline operator double ( ) const { return 0; }
175 __forceinline operator float ( ) const { return 0; }
176 __forceinline operator long long( ) const { return 0; }
177 __forceinline operator unsigned long long( ) const { return 0; }
178 __forceinline operator long ( ) const { return 0; }
179 __forceinline operator unsigned long ( ) const { return 0; }
180 __forceinline operator int ( ) const { return 0; }
181 __forceinline operator unsigned int ( ) const { return 0; }
182 __forceinline operator short ( ) const { return 0; }
183 __forceinline operator unsigned short ( ) const { return 0; }
184 __forceinline operator char ( ) const { return 0; }
185 __forceinline operator unsigned char ( ) const { return 0; }
186 };
187
188 const constexpr StepTy step = StepTy();
189
190 struct ReverseStepTy {
191 };
192
193 const constexpr ReverseStepTy reverse_step = ReverseStepTy();
194
195 struct EmptyTy {
196 };
197
198 const constexpr EmptyTy empty = EmptyTy();
199
200 struct FullTy {
201 };
202
203 const constexpr FullTy full = FullTy();
204
205 struct UndefinedTy {
206 };
207
208 const constexpr UndefinedTy undefined = UndefinedTy();
209}
210