All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
math.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef ARCH_MATH_H
25 #define ARCH_MATH_H
26 
30 
31 #include "pxr/pxr.h"
32 #include "pxr/base/arch/defines.h"
33 #include "pxr/base/arch/inttypes.h"
34 
35 #include <cmath>
36 #if !defined(M_PI)
37 #define M_PI 3.14159265358979323846
38 #endif
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
44 
45 #if defined (ARCH_CPU_INTEL) || defined(doxygen)
46 
49 #define ARCH_MIN_FLOAT_EPS_SQR 0.000244141F
50 
52 inline long ArchSign(long val) {
53  return (val > 0) - (val < 0);
54 }
55 
58 inline uint32_t ArchFloatToBitPattern(float v) {
59  union {
60  float _float;
61  uint32_t _uint;
62  } value;
63  value._float = v;
64  return value._uint;
65 }
66 
69 inline float ArchBitPatternToFloat(uint32_t v) {
70  union {
71  uint32_t _uint;
72  float _float;
73  } value;
74  value._uint = v;
75  return value._float;
76 }
77 
80 inline uint64_t ArchDoubleToBitPattern(double v) {
81  union {
82  double _double;
83  uint64_t _uint;
84  } value;
85  value._double = v;
86  return value._uint;
87 }
88 
91 inline double ArchBitPatternToDouble(uint64_t v) {
92  union {
93  uint64_t _uint;
94  double _double;
95  } value;
96  value._uint = v;
97  return value._double;
98 }
99 
100 #else
101 #error Unknown system architecture.
102 #endif
103 
104 #if defined(ARCH_OS_LINUX) || defined(doxygen)
105 
107 inline void ArchSinCosf(float v, float *s, float *c) { sincosf(v, s, c); }
108 
110 inline void ArchSinCos(double v, double *s, double *c) { sincos(v, s, c); }
111 
112 #elif defined(ARCH_OS_DARWIN) || defined(ARCH_OS_WINDOWS)
113 
114 inline void ArchSinCosf(float v, float *s, float *c) {
115  *s = std::sin(v);
116  *c = std::cos(v);
117 }
118 inline void ArchSinCos(double v, double *s, double *c) {
119  *s = std::sin(v);
120  *c = std::cos(v);
121 }
122 
123 #else
124 #error Unknown architecture.
125 #endif
126 
128 
129 PXR_NAMESPACE_CLOSE_SCOPE
130 
131 #endif // ARCH_MATH_H
double ArchBitPatternToDouble(uint64_t v)
Returns The double precision floating point value corresponding to the given IEEE-754 bit pattern...
Definition: math.h:91
float ArchBitPatternToFloat(uint32_t v)
Returns The single precision floating point value corresponding to the given IEEE-754 bit pattern...
Definition: math.h:69
uint64_t ArchDoubleToBitPattern(double v)
Returns The IEEE-754 bit pattern of the specified double precision value as a 64-bit unsigned integer...
Definition: math.h:80
void ArchSinCosf(float v, float *s, float *c)
Computes the sine and cosine of the specified value as a float.
Definition: math.h:107
long ArchSign(long val)
Three-valued sign. Return 1 if val &gt; 0, 0 if val == 0, or -1 if val &lt; 0.
Definition: math.h:52
uint32_t ArchFloatToBitPattern(float v)
Returns The IEEE-754 bit pattern of the specified single precision value as a 32-bit unsigned integer...
Definition: math.h:58
void ArchSinCos(double v, double *s, double *c)
Computes the sine and cosine of the specified value as a double.
Definition: math.h:110