SSBM Decomp
Loading...
Searching...
No Matches
math_ppc.h
Go to the documentation of this file.
1#ifndef _MATH_PPC_H_
2#define _MATH_PPC_H_
3
5
6#ifdef __MWERKS__
7#pragma push
8#pragma cplusplus on
9#endif
10
11extern inline float sqrtf(float x)
12{
13 static const double _half = .5;
14 static const double _three = 3.0;
15 volatile float y;
16 if (x > 0.0f) {
17 double guess = __frsqrte((double) x); // returns an approximation to
18 guess = _half * guess *
19 (_three - guess * guess * x); // now have 12 sig bits
20 guess = _half * guess *
21 (_three - guess * guess * x); // now have 24 sig bits
22 guess = _half * guess *
23 (_three - guess * guess * x); // now have 32 sig bits
24 y = (float) (x * guess);
25 return y;
26 }
27 return x;
28}
29
30#ifdef __MWERKS__
31#pragma pop
32#endif
33
34inline float sqrtf_accurate(float x)
35{
36 volatile float y;
37 if (x > 0.0f) {
38 double guess = __frsqrte((double) x); // returns an approximation to
39 guess =
40 0.5 * guess * (3.0 - guess * guess * x); // now have 12 sig bits
41 guess =
42 0.5 * guess * (3.0 - guess * guess * x); // now have 24 sig bits
43 guess =
44 0.5 * guess * (3.0 - guess * guess * x); // now have 32 sig bits
45 guess = 0.5 * guess * (3.0 - guess * guess * x); // extra iteration
46 y = (float) (x * guess);
47 return y;
48 }
49 return x;
50}
51
52#endif
double __frsqrte(double)
float sqrtf(float x)
Definition math_ppc.h:11
float sqrtf_accurate(float x)
Definition math_ppc.h:34