aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/llmath.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmath/llmath.h
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmath/llmath.h')
-rw-r--r--linden/indra/llmath/llmath.h52
1 files changed, 43 insertions, 9 deletions
diff --git a/linden/indra/llmath/llmath.h b/linden/indra/llmath/llmath.h
index 4a6358d..82ab197 100644
--- a/linden/indra/llmath/llmath.h
+++ b/linden/indra/llmath/llmath.h
@@ -33,9 +33,10 @@
33#define LLMATH_H 33#define LLMATH_H
34 34
35#include <cmath> 35#include <cmath>
36//#include <math.h> 36#include <cstdlib>
37//#include <stdlib.h>
38#include "lldefs.h" 37#include "lldefs.h"
38#include "llstl.h" // *TODO: Remove when LLString is gone
39#include "llstring.h" // *TODO: Remove when LLString is gone
39 40
40// work around for Windows & older gcc non-standard function names. 41// work around for Windows & older gcc non-standard function names.
41#if LL_WINDOWS 42#if LL_WINDOWS
@@ -93,6 +94,9 @@ const F32 F_APPROXIMATELY_ZERO = 0.00001f;
93const F32 F_LN2 = 0.69314718056f; 94const F32 F_LN2 = 0.69314718056f;
94const F32 OO_LN2 = 1.4426950408889634073599246810019f; 95const F32 OO_LN2 = 1.4426950408889634073599246810019f;
95 96
97const F32 F_ALMOST_ZERO = 0.0001f;
98const F32 F_ALMOST_ONE = 1.0f - F_ALMOST_ZERO;
99
96// BUG: Eliminate in favor of F_APPROXIMATELY_ZERO above? 100// BUG: Eliminate in favor of F_APPROXIMATELY_ZERO above?
97const F32 FP_MAG_THRESHOLD = 0.0000001f; 101const F32 FP_MAG_THRESHOLD = 0.0000001f;
98 102
@@ -102,13 +106,13 @@ inline BOOL is_approx_zero( F32 f ) { return (-F_APPROXIMATELY_ZERO < f) && (f <
102inline BOOL is_approx_equal(F32 x, F32 y) 106inline BOOL is_approx_equal(F32 x, F32 y)
103{ 107{
104 const S32 COMPARE_MANTISSA_UP_TO_BIT = 0x02; 108 const S32 COMPARE_MANTISSA_UP_TO_BIT = 0x02;
105 return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); 109 return (std::abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT);
106} 110}
107 111
108inline BOOL is_approx_equal(F64 x, F64 y) 112inline BOOL is_approx_equal(F64 x, F64 y)
109{ 113{
110 const S64 COMPARE_MANTISSA_UP_TO_BIT = 0x02; 114 const S64 COMPARE_MANTISSA_UP_TO_BIT = 0x02;
111 return (abs((S32) ((U64&)x - (U64&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); 115 return (std::abs((S32) ((U64&)x - (U64&)y) ) < COMPARE_MANTISSA_UP_TO_BIT);
112} 116}
113 117
114inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) 118inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits)
@@ -155,17 +159,17 @@ inline BOOL is_approx_equal_fraction(F64 x, F64 y, U32 frac_bits)
155 159
156inline S32 llabs(const S32 a) 160inline S32 llabs(const S32 a)
157{ 161{
158 return S32(labs(a)); 162 return S32(std::labs(a));
159} 163}
160 164
161inline F32 llabs(const F32 a) 165inline F32 llabs(const F32 a)
162{ 166{
163 return F32(fabs(a)); 167 return F32(std::fabs(a));
164} 168}
165 169
166inline F64 llabs(const F64 a) 170inline F64 llabs(const F64 a)
167{ 171{
168 return F64(fabs(a)); 172 return F64(std::fabs(a));
169} 173}
170 174
171inline S32 lltrunc( F32 f ) 175inline S32 lltrunc( F32 f )
@@ -473,8 +477,8 @@ inline F32 llsimple_angle(F32 angle)
473 return angle; 477 return angle;
474} 478}
475 479
476//calculate the nearesr power of two number for val, bounded by max_power_two 480//SDK - Renamed this to get_lower_power_two, since this is what this actually does.
477inline U32 get_nearest_power_two(U32 val, U32 max_power_two) 481inline U32 get_lower_power_two(U32 val, U32 max_power_two)
478{ 482{
479 if(!max_power_two) 483 if(!max_power_two)
480 { 484 {
@@ -489,4 +493,34 @@ inline U32 get_nearest_power_two(U32 val, U32 max_power_two)
489 493
490 return max_power_two ; 494 return max_power_two ;
491} 495}
496
497// calculate next highest power of two, limited by max_power_two
498// This is taken from a brilliant little code snipped on http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
499// Basically we convert the binary to a solid string of 1's with the same
500// number of digits, then add one. We subtract 1 initially to handle
501// the case where the number passed in is actually a power of two.
502// WARNING: this only works with 32 bit ints.
503inline U32 get_next_power_two(U32 val, U32 max_power_two)
504{
505 if(!max_power_two)
506 {
507 max_power_two = 1 << 31 ;
508 }
509
510 if(val >= max_power_two)
511 {
512 return max_power_two;
513 }
514
515 val--;
516 val = (val >> 1) | val;
517 val = (val >> 2) | val;
518 val = (val >> 4) | val;
519 val = (val >> 8) | val;
520 val = (val >> 16) | val;
521 val++;
522
523 return val;
524}
525
492#endif 526#endif