ReactOS  0.4.14-dev-50-g13bb5e2
mmath.c File Reference
#include "GL/gl.h"
#include "mmath.h"
Include dependency graph for mmath.c:

Go to the source code of this file.

Functions

static void init_sqrt (void)
 
float gl_sqrt (float x)
 
void gl_init_math (void)
 

Variables

static short sqrttab [0x100]
 

Function Documentation

◆ gl_init_math()

void gl_init_math ( void  )

Definition at line 140 of file mmath.c.

141 {
142  static GLboolean initialized = GL_FALSE;
143 
144  if (!initialized) {
145  init_sqrt();
146 
147 
149  }
150 }
#define GL_FALSE
Definition: gl.h:173
unsigned char GLboolean
Definition: gl.h:151
static BOOL initialized
Definition: syslog.c:39
#define GL_TRUE
Definition: gl.h:174
static void init_sqrt(void)
Definition: mmath.c:63

Referenced by gl_create_context().

◆ gl_sqrt()

float gl_sqrt ( float  x)

Definition at line 104 of file mmath.c.

105 {
106 #ifdef FAST_MATH
107  unsigned int *num = (unsigned int *)&x;
108  /* to access the bits of a float in C
109  * we must misuse pointers */
110 
111  short e; /* the exponent */
112  if (x == 0.0F) return 0.0F; /* check for square root of 0 */
113  e = (*num >> 23) - 127; /* get the exponent - on a SPARC the */
114  /* exponent is stored with 127 added */
115  *num &= 0x7fffff; /* leave only the mantissa */
116  if (e & 0x01) *num |= 0x800000;
117  /* the exponent is odd so we have to */
118  /* look it up in the second half of */
119  /* the lookup table, so we set the */
120  /* high bit */
121  e >>= 1; /* divide the exponent by two */
122  /* note that in C the shift */
123  /* operators are sign preserving */
124  /* for signed operands */
125  /* Do the table lookup, based on the quaternary mantissa,
126  * then reconstruct the result back into a float
127  */
128  *num = ((sqrttab[*num >> 16]) << 16) | ((e + 127) << 23);
129  return x;
130 #else
131  return sqrt(x);
132 #endif
133 }
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define e
Definition: ke_i.h:82
static short sqrttab[0x100]
Definition: mmath.c:61
GLuint GLuint num
Definition: glext.h:9618
#define F(x, y, z)
Definition: md5.c:51

◆ init_sqrt()

static void init_sqrt ( void  )
static

Definition at line 63 of file mmath.c.

64 {
65 #ifdef FAST_MATH
66  unsigned short i;
67  float f;
68  unsigned int *fi = (unsigned int *)&f;
69  /* to access the bits of a float in */
70  /* C quickly we must misuse pointers */
71 
72  for(i=0; i<= 0x7f; i++) {
73  *fi = 0;
74 
75  /*
76  * Build a float with the bit pattern i as mantissa
77  * and an exponent of 0, stored as 127
78  */
79 
80  *fi = (i << 16) | (127 << 23);
81  f = sqrt(f);
82 
83  /*
84  * Take the square root then strip the first 7 bits of
85  * the mantissa into the table
86  */
87 
88  sqrttab[i] = (*fi & 0x7fffff) >> 16;
89 
90  /*
91  * Repeat the process, this time with an exponent of
92  * 1, stored as 128
93  */
94 
95  *fi = 0;
96  *fi = (i << 16) | (128 << 23);
97  f = sqrt(f);
98  sqrttab[i+0x80] = (*fi & 0x7fffff) >> 16;
99  }
100 #endif /*FAST_MATH*/
101 }
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static short sqrttab[0x100]
Definition: mmath.c:61
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83

Referenced by gl_init_math().

Variable Documentation

◆ sqrttab

short sqrttab[0x100]
static

Definition at line 61 of file mmath.c.

Referenced by gl_sqrt(), and init_sqrt().