HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
UT_ISqrt.h
Go to the documentation of this file.
1
/*
2
* PROPRIETARY INFORMATION. This software is proprietary to
3
* Side Effects Software Inc., and is not to be reproduced,
4
* transmitted, or disclosed in any way without written permission.
5
*
6
* NAME: UT library (C++)
7
*
8
* COMMENTS: Fast lookup to get integer square roots. The square roots
9
* will round, thus UTisqrt(3) = 2, UTisqrt(2) = 1
10
* The table is good for positive integers up to 1024
11
*
12
*/
13
14
#ifndef __UT_ISqrt_h__
15
#define __UT_ISqrt_h__
16
17
#include "
UT_API.h
"
18
#include <
SYS/SYS_Types.h
>
19
#include <
SYS/SYS_Math.h
>
20
21
// In its previous life, UTisqrt() used a table lookup for values less than
22
// 1024, and for the rest, fell back to algorithms from:
23
// http://www.azillionmonkeys.com/qed/sqroot.html
24
// However modern hardware has better and more consistent performance computing
25
// floating point double precision. The double precision sqrt() is on par in
26
// performance with the table lookup and considerably faster than the integer
27
// based algorithms.
28
//
29
// One major difference (and flaw with the previous algorithm) was that the LUT
30
// was built using rounding, while the fall back algorithm rounded to zero.
31
// The current algorithm uses round to zero for all values.
32
static
inline
int
33
UTisqrt(
uint
val
)
34
{
35
// Use double precision so that the uint precision is fully represented in
36
// the mantissa.
37
return
(
int
)SYSsqrt(
double
(val));
38
}
39
40
static
inline
float
41
UTinverseSqrt(
uint
val)
42
{
43
// Use double precision so that the uint precision is fully represented in
44
// the mantissa.
45
return
SYSsaferecip(SYSsqrt(
double
(val)));
46
}
47
48
#endif
UT_API.h
SYS_Math.h
SYS_Types.h
val
GLuint GLfloat * val
Definition:
glcorearb.h:1608
uint
unsigned int uint
Definition:
SYS_Types.h:45
UT
UT_ISqrt.h
Generated on Sun Nov 17 2024 03:03:42 for HDK by
1.8.6