OpenWareLaboratory
fastpow.c
Go to the documentation of this file.
1 
14 #include "fastpow.h"
15 #include <math.h>
16 
17 static const float _2p23 = 8388608.0f;
18 
20 (
21  uint32_t* const pTable,
22  const uint32_t precision
23 )
24 {
25  /* step along table elements and x-axis positions */
26  float zeroToOne = 1.0f / ((float)(1 << precision) * 2.0f); /* A */
27  int32_t i; /* B */
28  for( i = 0; i < (1 << precision); ++i ) /* C */
29  {
30  /* make y-axis value for table element */
31  const float f = ((float)powf( 2.0f, zeroToOne ) - 1.0f) * _2p23;
32  pTable[i] = (uint32_t)( f < _2p23 ? f : (_2p23 - 1.0f) );
33  zeroToOne += 1.0f / (float)(1 << precision);
34  } /* D */
35 }
36 
46 (
47  const float val,
48  const float ilog2,
49  const uint32_t* pTable,
50  const uint32_t precision
51 )
52 {
53  /* build float bits */
54  const int32_t i = (int32_t)( (val * (_2p23 * ilog2)) + (127.0f * _2p23) );
55 
56  /* replace mantissa with lookup */
57  const int32_t it = (i & 0xFF800000) | pTable[(i & 0x7FFFFF) >> /* E */
58  (23 - precision)]; /* F */
59 
60  /* convert bits to float */
61  return *(const float*)( &it );
62 }
static const float _2p23
http://www.hxa.name/articles/content/fast-pow-adjustable_hxa7241_2007.html
Definition: fastpow.c:17
float powFastLookup(const float val, const float ilog2, const uint32_t *pTable, const uint32_t precision)
Get pow (fast!).
Definition: fastpow.c:46
void powFastSetTable(uint32_t *const pTable, const uint32_t precision)
Definition: fastpow.c:20