22#ifndef PQ_FAST_MATH_H_
23#define PQ_FAST_MATH_H_
25#include "pq_globals.h"
26#include "pq_fixed32_trig.h"
35inline float fastSqrt(
const float& n)
37 static union {int32_t i;
float f;} u;
38 u.i = 0x2035AD0C + (*(int32_t*)&n >> 1);
39 return n / u.f + u.f * 0.25f;
42inline float fastSin(
float x) {
43#if defined(PQ_ARCH_32BITS)
44 x = wrap01(x/TWO_PI) * 4294967295ULL;
45 return sin32( (uint32_t)x ) / 2147483532.0f;
47 x = wrap01(x/TWO_PI) * 65535;
48 return sin16( (uint16_t)x ) / 32767.0f;
52inline float fastCos(
float x) {
53 return fastSin(HALF_PI - x);
57inline double fastPow(
double a,
double b) {
62 u.x[1] = (int32_t)(b * (u.x[1] - 1072632447) + 1072632447);
67inline float fastPow(
float a,
float b) {
68 return (
float)fastPow((
double)a, (
double)b);
75inline float fastExp(
float x)
77 constexpr float a = (1 << 23) / 0.69314718f;
78 constexpr float b = (1 << 23) * (127 - 0.043677448f);
82 constexpr float c = (1 << 23);
83 constexpr float d = (1 << 23) * 255;
85 x = (x < c) ? 0.0f : d;
88 uint32_t n =
static_cast<uint32_t
>(x);