diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmath/llmath.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/linden/indra/llmath/llmath.h b/linden/indra/llmath/llmath.h index d3c0d86..4a6358d 100644 --- a/linden/indra/llmath/llmath.h +++ b/linden/indra/llmath/llmath.h | |||
@@ -32,8 +32,14 @@ | |||
32 | #ifndef LLMATH_H | 32 | #ifndef LLMATH_H |
33 | #define LLMATH_H | 33 | #define LLMATH_H |
34 | 34 | ||
35 | #include <cmath> | ||
36 | //#include <math.h> | ||
37 | //#include <stdlib.h> | ||
38 | #include "lldefs.h" | ||
39 | |||
35 | // work around for Windows & older gcc non-standard function names. | 40 | // work around for Windows & older gcc non-standard function names. |
36 | #if LL_WINDOWS | 41 | #if LL_WINDOWS |
42 | #include <float.h> | ||
37 | #define llisnan(val) _isnan(val) | 43 | #define llisnan(val) _isnan(val) |
38 | #define llfinite(val) _finite(val) | 44 | #define llfinite(val) _finite(val) |
39 | #elif (LL_LINUX && __GNUC__ <= 2) | 45 | #elif (LL_LINUX && __GNUC__ <= 2) |
@@ -99,6 +105,12 @@ inline BOOL is_approx_equal(F32 x, F32 y) | |||
99 | return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); | 105 | return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); |
100 | } | 106 | } |
101 | 107 | ||
108 | inline BOOL is_approx_equal(F64 x, F64 y) | ||
109 | { | ||
110 | const S64 COMPARE_MANTISSA_UP_TO_BIT = 0x02; | ||
111 | return (abs((S32) ((U64&)x - (U64&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); | ||
112 | } | ||
113 | |||
102 | inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) | 114 | inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) |
103 | { | 115 | { |
104 | BOOL ret = TRUE; | 116 | BOOL ret = TRUE; |
@@ -120,6 +132,27 @@ inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) | |||
120 | return ret; | 132 | return ret; |
121 | } | 133 | } |
122 | 134 | ||
135 | inline BOOL is_approx_equal_fraction(F64 x, F64 y, U32 frac_bits) | ||
136 | { | ||
137 | BOOL ret = TRUE; | ||
138 | F64 diff = (F64) fabs(x - y); | ||
139 | |||
140 | S32 diffInt = (S32) diff; | ||
141 | S32 diffFracTolerance = (S32) ((diff - (F64) diffInt) * (1 << frac_bits)); | ||
142 | |||
143 | // if integer portion is not equal, not enough bits were used for packing | ||
144 | // so error out since either the use case is not correct OR there is | ||
145 | // an issue with pack/unpack. should fail in either case. | ||
146 | // for decimal portion, make sure that the delta is no more than 1 | ||
147 | // based on the number of bits used for packing decimal portion. | ||
148 | if (diffInt != 0 || diffFracTolerance > 1) | ||
149 | { | ||
150 | ret = FALSE; | ||
151 | } | ||
152 | |||
153 | return ret; | ||
154 | } | ||
155 | |||
123 | inline S32 llabs(const S32 a) | 156 | inline S32 llabs(const S32 a) |
124 | { | 157 | { |
125 | return S32(labs(a)); | 158 | return S32(labs(a)); |