xsmath.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSMATH_H
66 #define XSMATH_H
67 
68 #include "xstypesconfig.h"
69 #include "xstypedefs.h"
70 #include "pstdint.h"
71 #include <math.h>
72 #include <float.h>
73 #include "xsfloatmath.h"
74 
75 #if defined(SQUISHCOCO)
76  #define XSMATHCONST static const
77  #define XSMATHINLINE2 static
78  #define XSMATHINLINE static
79  #define WANTXSMATH2 1
80 #else // normal operation
81  #if defined( __cplusplus)
82  #if defined(__ADSP21000__)
83  #define XSMATHCONST static const
84  #define XSMATHINLINE inline static
85  #define WANTXSMATH2 0
86  #elif defined(__ANDROID_API__) || defined(__APPLE__)
87  #define XSMATHCONST static constexpr
88  #define XSMATHINLINE inline static
89  #define WANTXSMATH2 1
90  #elif defined(__AVR32__)
91  #define XSMATHCONST static const
92  #define XSMATHINLINE inline static
93  #define WANTXSMATH2 0
94  #else
95  #define XSMATHCONST static constexpr
96  #define XSMATHINLINE inline static constexpr
97  #define WANTXSMATH2 1
98  #endif
99  #define XSMATHINLINE2 inline static
100  #else
101  #define XSMATHCONST static const
102  #define XSMATHINLINE static
103  #define XSMATHINLINE2 static
104  #define WANTXSMATH2 0
105  #endif
106 #endif
107 
115 XSMATHCONST XsReal XsMath_e = 2.7182818284590452353602874713527;
118 XSMATHCONST XsReal XsMath_pi = 3.1415926535897932384626433832795028841971693993751058209749;
123 
124 #ifdef XSENS_SINGLE_PRECISION
125  XSMATHCONST XsReal XsMath_epsilon = 1.192092895507813e-07;
128  XSMATHCONST XsReal XsMath_sqrtEpsilon = 3.452669830012439e-04;
132  XSMATHCONST XsReal XsMath_sqrtDenormalized = 3.1622776601683793319988935444327e-19;
133 #else
134  XSMATHCONST XsReal XsMath_epsilon = 2.2204460492503131e-016;
137  XSMATHCONST XsReal XsMath_sqrtEpsilon = 1.4901161193847656e-008;
141  XSMATHCONST XsReal XsMath_sqrtDenormalized = 3.1622776601683793319988935444327e-154;
142 #endif
143 
145 XSMATHCONST XsReal XsMath_rad2degValue = 57.295779513082320876798154814105; // (180.0/pi)
147 XSMATHCONST XsReal XsMath_deg2radValue = 0.017453292519943295769236907684886; // (pi/180.0)
148 
167 
169 XSMATHCONST XsReal XsMath_minusHalfPi = -1.5707963267948966192313216916397514420985846996875529104874;
171 XSMATHCONST XsReal XsMath_halfPi = 1.5707963267948966192313216916397514420985846996875529104874;
173 XSMATHCONST XsReal XsMath_twoPi = 6.2831853071795864769252867665590057683943387987502116419498;
175 XSMATHCONST XsReal XsMath_sqrt2 = 1.4142135623730950488016887242097;
177 XSMATHCONST XsReal XsMath_sqrtHalf = 0.5 * 1.4142135623730950488016887242097;
178 
179 #ifdef XSENS_SINGLE_PRECISION
182 #else
185 #endif
186 
190 {
191  return x <= XsMath_minusOne ? XsMath_minusHalfPi : x >= XsMath_one ? XsMath_halfPi : asin(x);
192 }
193 
197 {
198  return XsMath_rad2degValue * radians;
199 }
200 
204 {
205  return XsMath_deg2radValue * degrees;
206 }
207 
211 {
212  return a * a;
213 }
214 
218 {
219  return a * a * a;
220 }
221 
225 {
226  return XsMath_pow2(a) * XsMath_pow3(a);
227 }
228 
232 {
233 #ifdef _MSC_VER
234  switch (_fpclass(x))
235  {
236  case _FPCLASS_SNAN:
237  case _FPCLASS_QNAN:
238  case _FPCLASS_NINF:
239  case _FPCLASS_PINF:
240  return 0;
241 
242  case _FPCLASS_NN:
243  case _FPCLASS_ND:
244  case _FPCLASS_NZ:
245  case _FPCLASS_PZ:
246  case _FPCLASS_PD:
247  case _FPCLASS_PN:
248  return 1;
249 
250  default:
251  return _finite(x);
252  }
253 #elif defined(isfinite) || defined(__APPLE__)
254  return isfinite(x);
255 #elif defined(__ANDROID_API__)
256  return finite(x);
257 #elif __GNUC__
258 #ifdef __cplusplus
259  return std::isfinite(x);
260 #else
261  return isfinite(x);
262 #endif
263 #elif defined(_ADI_COMPILER)
264  return !(isnan(x) || isinf(x));
265 #else
266  return 1;
267 #endif
268 }
269 
273 {
274  return (d >= 0) ? (int32_t) floorf(d + 0.5f) : (int32_t) ceilf(d - 0.5f);
275 }
276 
280 {
281  return (d >= 0) ? (int64_t) floorf(d + 0.5f) : (int64_t) ceilf(d - 0.5f);
282 }
283 
287 {
288  return (d >= 0) ? (int32_t) floor(d + 0.5) : (int32_t) ceil(d - 0.5);
289 }
290 
294 {
295  return (d >= 0) ? (int64_t) floor(d + 0.5) : (int64_t) ceil(d - 0.5);
296 }
297 
298 #ifdef __cplusplus
299  #ifndef XSMATH2_H
300  #include "xsmath2.h"
301  #endif
302 #endif
303 
306 #endif
XsMath_pi
XSMATHCONST XsReal XsMath_pi
The value pi.
Definition: xsmath.h:118
XsMath_asinClamped
XSMATHINLINE XsReal XsMath_asinClamped(const XsReal x)
Returns asin(x) for -1 < x < 1.
Definition: xsmath.h:189
XsMath_twoPi
XSMATHCONST XsReal XsMath_twoPi
2*pi
Definition: xsmath.h:173
XsMath_one
XSMATHCONST XsReal XsMath_one
1.0
Definition: xsmath.h:158
XsMath_sqrtEpsilon
XSMATHCONST XsReal XsMath_sqrtEpsilon
Square root of XsMath_epsilon.
Definition: xsmath.h:137
XsMath_sqrtDenormalized
XSMATHCONST XsReal XsMath_sqrtDenormalized
Square root of XsMath_denormalized.
Definition: xsmath.h:141
XsMath_doubleToInt64
XSMATHINLINE2 int64_t XsMath_doubleToInt64(double d)
Returns d integer converted from a double precision floating point value.
Definition: xsmath.h:293
XsMath_minusPt5
XSMATHCONST XsReal XsMath_minusPt5
-0.5
Definition: xsmath.h:156
XsMath_minusTwo
XSMATHCONST XsReal XsMath_minusTwo
-2
Definition: xsmath.h:166
xstypedefs.h
XsMath_sqrt2
XSMATHCONST XsReal XsMath_sqrt2
sqrt(2)
Definition: xsmath.h:175
xsfloatmath.h
XsMath_tinyValue
XSMATHCONST XsReal XsMath_tinyValue
A really small value.
Definition: xsmath.h:120
f
f
XSMATHINLINE
#define XSMATHINLINE
Definition: xsmath.h:102
XsMath_pow3
XSMATHINLINE XsReal XsMath_pow3(XsReal a)
Returns a to the power of 3.
Definition: xsmath.h:217
XsMath_minusOne
XSMATHCONST XsReal XsMath_minusOne
-1.0
Definition: xsmath.h:160
XsMath_denormalized
XSMATHCONST XsReal XsMath_denormalized
Value that represents the subnormal number in floating point wizardry.
Definition: xsmath.h:139
XsMath_pt5
XSMATHCONST XsReal XsMath_pt5
0.5
Definition: xsmath.h:154
XSMATHINLINE2
#define XSMATHINLINE2
Definition: xsmath.h:103
XsMath_rad2deg
XSMATHINLINE XsReal XsMath_rad2deg(XsReal radians)
Convert radians to degrees.
Definition: xsmath.h:196
XsReal
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:73
XsMath_pt25
XSMATHCONST XsReal XsMath_pt25
0.25
Definition: xsmath.h:152
d
d
XsMath_infinity
XSMATHCONST XsReal XsMath_infinity
infinity value
Definition: xsmath.h:184
XsMath_doubleToLong
XSMATHINLINE2 int32_t XsMath_doubleToLong(double d)
Returns d integer converted from a double precision floating point value.
Definition: xsmath.h:286
XsMath_e
XSMATHCONST XsReal XsMath_e
The value e.
Definition: xsmath.h:116
XsMath_floatToInt64
XSMATHINLINE2 int64_t XsMath_floatToInt64(float d)
Returns d integer converted from a single precision floating point value.
Definition: xsmath.h:279
xstypesconfig.h
pstdint.h
XsMath_two
XSMATHCONST XsReal XsMath_two
2
Definition: xsmath.h:162
XsMath_epsilon
XSMATHCONST XsReal XsMath_epsilon
A value related to the precision of floating point arithmetic (2.2204460492503131e-016)
Definition: xsmath.h:135
XsMath_floatToLong
XSMATHINLINE2 int32_t XsMath_floatToLong(float d)
Returns d integer converted from a single precision floating point value.
Definition: xsmath.h:272
XsMath_minusHalfPi
XSMATHCONST XsReal XsMath_minusHalfPi
-pi/2
Definition: xsmath.h:169
XsMath_zero
XSMATHCONST XsReal XsMath_zero
0
Definition: xsmath.h:150
XsMath_pow5
XSMATHINLINE XsReal XsMath_pow5(XsReal a)
Returns a to the power of 5.
Definition: xsmath.h:224
XsMath_isFinite
XSMATHINLINE2 int XsMath_isFinite(XsReal x)
Returns non-zero if x is finite.
Definition: xsmath.h:231
XsMath_pow2
XSMATHINLINE XsReal XsMath_pow2(XsReal a)
Returns a to the power of 2.
Definition: xsmath.h:210
XsMath_sqrtHalf
XSMATHCONST XsReal XsMath_sqrtHalf
sqrt(0.5)
Definition: xsmath.h:177
XsMath_hugeValue
XSMATHCONST XsReal XsMath_hugeValue
A convincingly large number.
Definition: xsmath.h:122
xsmath2.h
int32_t
signed int int32_t
Definition: pstdint.h:515
XsMath_deg2rad
XSMATHINLINE XsReal XsMath_deg2rad(XsReal degrees)
Convert degrees to radians.
Definition: xsmath.h:203
XsMath_halfPi
XSMATHCONST XsReal XsMath_halfPi
pi/2
Definition: xsmath.h:171
XsMath_rad2degValue
XSMATHCONST XsReal XsMath_rad2degValue
Value to convert radians to degrees by multiplication.
Definition: xsmath.h:145
XsMath_deg2radValue
XSMATHCONST XsReal XsMath_deg2radValue
Value to convert degrees to radians by multiplication.
Definition: xsmath.h:147
XSMATHCONST
#define XSMATHCONST
Definition: xsmath.h:101
XsMath_four
XSMATHCONST XsReal XsMath_four
4
Definition: xsmath.h:164


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20