summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
authorAaron Brashears <aaronb@lindenlab.com>2007-05-03 21:48:14 +0000
committerAaron Brashears <aaronb@lindenlab.com>2007-05-03 21:48:14 +0000
commit08d746156b56d8b72919af8cbca25609c855ef82 (patch)
tree51d4c6d06b87b5477e3c61d42ee49de19a2d72b6 /indra/llmath
parent5de49ccb321aba6f09111e74abbb965b630f8d27 (diff)
Result of svn merge -r59717:60410 svn+ssh://svn/svn/linden/branches/adroit.2007-03-13 into release.
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/llmath.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index ad8ced9e1a..5fd365086f 100644
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -79,6 +79,27 @@ inline BOOL is_approx_equal(F32 x, F32 y)
return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT);
}
+inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits)
+{
+ BOOL ret = TRUE;
+ F32 diff = (F32) fabs(x - y);
+
+ S32 diffInt = (S32) diff;
+ S32 diffFracTolerance = (S32) ((diff - (F32) diffInt) * (1 << frac_bits));
+
+ // if integer portion is not equal, not enough bits were used for packing
+ // so error out since either the use case is not correct OR there is
+ // an issue with pack/unpack. should fail in either case.
+ // for decimal portion, make sure that the delta is no more than 1
+ // based on the number of bits used for packing decimal portion.
+ if (diffInt != 0 || diffFracTolerance > 1)
+ {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
inline S32 llabs(const S32 a)
{
return S32(labs(a));