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 extern MAYBE_UNUSED TrueTy True;
28
29 struct FalseTy {
30 __forceinline operator bool( ) const { return false; }
31 };
32
33 extern MAYBE_UNUSED FalseTy False;
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 extern MAYBE_UNUSED ZeroTy zero;
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 extern MAYBE_UNUSED OneTy one;
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 extern MAYBE_UNUSED NegInfTy neg_inf;
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 extern MAYBE_UNUSED PosInfTy inf;
107 extern MAYBE_UNUSED PosInfTy pos_inf;
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 extern MAYBE_UNUSED NaNTy nan;
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 extern MAYBE_UNUSED UlpTy ulp;
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 extern MAYBE_UNUSED PiTy pi;
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 extern MAYBE_UNUSED OneOverPiTy one_over_pi;
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 extern MAYBE_UNUSED TwoPiTy two_pi;
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 extern MAYBE_UNUSED OneOverTwoPiTy one_over_two_pi;
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 extern MAYBE_UNUSED FourPiTy four_pi;
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 extern MAYBE_UNUSED OneOverFourPiTy one_over_four_pi;
172
173 struct StepTy {
174 };
175
176 extern MAYBE_UNUSED StepTy step;
177
178 struct ReverseStepTy {
179 };
180
181 extern MAYBE_UNUSED ReverseStepTy reverse_step;
182
183 struct EmptyTy {
184 };
185
186 extern MAYBE_UNUSED EmptyTy empty;
187
188 struct FullTy {
189 };
190
191 extern MAYBE_UNUSED FullTy full;
192
193 struct UndefinedTy {
194 };
195
196 extern MAYBE_UNUSED UndefinedTy undefined;
197}
198

source code of qtquick3d/src/3rdparty/embree/common/math/constants.h