musl/src/math/scalbnf.c
nsz 8051e08e10 simplify scalbn*.c implementations
The old scalbn.c was wrong and slow, the new one is just slow.
(scalbn(0x1p+1023,-2097) should give 0x1p-1074, but the old code gave 0)
2012-03-19 10:54:07 +01:00

29 lines
427 B
C

#include "libm.h"
float scalbnf(float x, int n)
{
float scale;
if (n > 127) {
x *= 0x1p127f;
n -= 127;
if (n > 127) {
x *= 0x1p127f;
n -= 127;
if (n > 127)
return x * 0x1p127f;
}
} else if (n < -126) {
x *= 0x1p-126f;
n += 126;
if (n < -126) {
x *= 0x1p-126f;
n += 126;
if (n < -126)
return x * 0x1p-126f;
}
}
SET_FLOAT_WORD(scale, (uint32_t)(0x7f+n)<<23);
return x * scale;
}