Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions fastapprox/src/fastexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@
static inline float
fastpow2 (float p)
{
float offset = (p < 0) ? 1.0f : 0.0f;
float clipp = (p < -126) ? -126.0f : p;
int w = clipp;
float z = clipp - w + offset;
union { uint32_t i; float f; } v = { cast_uint32_t ( (1 << 23) * (clipp + 121.2740575f + 27.7280233f / (4.84252568f - z) - 1.49012907f * z) ) };

return v.f;
union {float f; uint32_t i;} xv = {p + 383.f}, zv;
zv.i = 0x3f800000u | ((xv.i & 0x7fffu) << 8u);
xv.f = xv.f - 4.23579f + 27.7280f / (5.84252568f - zv.f) - 1.49012907f * zv.f;
xv.i = ((((xv.i < 0x43808000u) ? 0u : xv.i) << 8u) & 0x7FFFFF00);
return xv.f;
}

static inline float
Expand All @@ -69,9 +67,9 @@ fastexp (float p)
static inline float
fasterpow2 (float p)
{
float clipp = (p < -126) ? -126.0f : p;
union { uint32_t i; float f; } v = { cast_uint32_t ( (1 << 23) * (clipp + 126.94269504f) ) };
return v.f;
union {float f; uint32_t i;} xv = {p + 382.95695f};
xv.i = ((((xv.i < 0x43808000u) ? 0u : xv.i) << 8u) & 0x7FFFFF00);
return xv.f;
}

static inline float
Expand Down
29 changes: 13 additions & 16 deletions fastapprox/src/fastlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
static inline float
fastlog2 (float x)
{
union { float f; uint32_t i; } vx = { x };
union { uint32_t i; float f; } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };
float y = vx.i;
y *= 1.1920928955078125e-7f;

return y - 124.22551499f
- 1.498030302f * mx.f
- 1.72587999f / (0.3520887068f + mx.f);
union {float f; uint32_t i;} xv = {x}, lv, mx;
mx.i = 0x3f000000u | (xv.i & 0x007FFFFFu);
lv.i = 0x43800000u | (xv.i >> 8u);

return lv.f - 380.22544f
- 1.498030302f * mx.f
- 1.72587999f / (0.3520887068f + mx.f);
}

static inline float
Expand All @@ -66,21 +65,19 @@ fastlog (float x)
static inline float
fasterlog2 (float x)
{
union { float f; uint32_t i; } vx = { x };
float y = vx.i;
y *= 1.1920928955078125e-7f;
return y - 126.94269504f;
union {float f; uint32_t i;} xv = {x}, lv;
lv.i = 0x43800000u | (xv.i >> 8u);
return (lv.f - 382.95695f);
}

static inline float
fasterlog (float x)
{
// return 0.69314718f * fasterlog2 (x);

union { float f; uint32_t i; } vx = { x };
float y = vx.i;
y *= 8.2629582881927490e-8f;
return y - 87.989971088f;
union {float f; uint32_t i;} xv = {x}, lv;
lv.i = 0x43800000u | (xv.i >> 8u);
return 0.69314718f * (lv.f - 382.95695f);
}

#ifdef __SSE2__
Expand Down