mirror of
https://github.com/fluencelabs/musl
synced 2025-05-29 07:31:53 +00:00
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)
29 lines
427 B
C
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;
|
|
}
|