aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2013-03-17 09:07:55 -0700
committerChris Robinson <[email protected]>2013-03-17 09:07:55 -0700
commitbf54de498416146bb6057ef5589476d361e4c2e6 (patch)
tree408ed3732c9cbb3a14df93a7af3b465954ee52c9 /Alc
parenteb1080910e8319fcba580139a3a7a2f3c5e7761c (diff)
Use less math to clamp floats to -1...+1
The previous code could have issues as precision lowers. This should hopefully work better while only using one if check instead of two.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 282053c7..3cd70455 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -916,9 +916,9 @@ static __inline ALfloat aluF2F(ALfloat val)
{ return val; }
static __inline ALint aluF2I(ALfloat val)
{
- /* Clamp the value between -1 and +1. This handles that without branching. */
- val = val+1.0f - fabsf(val-1.0f);
- val = (val-2.0f + fabsf(val+2.0f)) * 0.25f;
+ /* Clamp the value between -1 and +1. This handles that with only a single branch. */
+ if(fabsf(val) > 1.0f)
+ val = (0.0f < val) - (val < 0.0f);
/* Convert to a signed integer, between -2147483647 and +2147483647. */
return fastf2i((ALfloat)(val*2147483647.0));
}