Files
semi-libc/src/math/scalbnf.c
T
Szabolcs Nagy c4359e0130 math: excess precision fix modf, modff, scalbn, scalbnf
old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
now we use STRICT_ASSIGN to work around the issue.
(see note 160 in c11 section 6.8.6.4)
2012-11-13 10:55:35 +01:00

34 lines
534 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) {
STRICT_ASSIGN(float, x, x * 0x1p127f);
return x;
}
}
} else if (n < -126) {
x *= 0x1p-126f;
n += 126;
if (n < -126) {
x *= 0x1p-126f;
n += 126;
if (n < -126) {
STRICT_ASSIGN(float, x, x * 0x1p-126f);
return x;
}
}
}
SET_FLOAT_WORD(scale, (uint32_t)(0x7f+n)<<23);
STRICT_ASSIGN(float, x, x * scale);
return x;
}