mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
27 lines
470 B
C
27 lines
470 B
C
module std::math::nolibc;
|
|
|
|
fn double scalbn(double x, int n) @weak @extname("scalbn")
|
|
{
|
|
switch
|
|
{
|
|
case n > 1023:
|
|
x *= 0x1p1023;
|
|
n -= 1023;
|
|
if (n > 1023)
|
|
{
|
|
x *= 0x1p1023;
|
|
n -= 1023;
|
|
if (n > 1023) n = 1023;
|
|
}
|
|
case n < -1022:
|
|
x *= 0x1p-1022 * 0x1p53;
|
|
n += 1022 - 53;
|
|
if (n < -1022)
|
|
{
|
|
x *= 0x1p-1022 * 0x1p53;
|
|
n += 1022 - 53;
|
|
if (n < -1022) n = -1022;
|
|
}
|
|
}
|
|
return x * bitcast(((ulong)(0x3ff + n)) << 52, double);
|
|
} |