diff options
Diffstat (limited to 'linden/indra/llmath/llmath.h')
-rw-r--r-- | linden/indra/llmath/llmath.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/linden/indra/llmath/llmath.h b/linden/indra/llmath/llmath.h index dbd825d..dd44e0c 100644 --- a/linden/indra/llmath/llmath.h +++ b/linden/indra/llmath/llmath.h | |||
@@ -99,6 +99,27 @@ inline BOOL is_approx_equal(F32 x, F32 y) | |||
99 | return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); | 99 | return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); |
100 | } | 100 | } |
101 | 101 | ||
102 | inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) | ||
103 | { | ||
104 | BOOL ret = TRUE; | ||
105 | F32 diff = (F32) fabs(x - y); | ||
106 | |||
107 | S32 diffInt = (S32) diff; | ||
108 | S32 diffFracTolerance = (S32) ((diff - (F32) diffInt) * (1 << frac_bits)); | ||
109 | |||
110 | // if integer portion is not equal, not enough bits were used for packing | ||
111 | // so error out since either the use case is not correct OR there is | ||
112 | // an issue with pack/unpack. should fail in either case. | ||
113 | // for decimal portion, make sure that the delta is no more than 1 | ||
114 | // based on the number of bits used for packing decimal portion. | ||
115 | if (diffInt != 0 || diffFracTolerance > 1) | ||
116 | { | ||
117 | ret = FALSE; | ||
118 | } | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
102 | inline S32 llabs(const S32 a) | 123 | inline S32 llabs(const S32 a) |
103 | { | 124 | { |
104 | return S32(labs(a)); | 125 | return S32(labs(a)); |