Skip to content

Commit c507b70

Browse files
committed
[CRT:MATH] Import frexp from musl
1 parent b734e3b commit c507b70

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

sdk/lib/crt/math/frexp.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
#include <math.h>
2-
#include <stdlib.h>
3-
#include <internal/ieee.h>
4-
51
/*
6-
* @implemented
2+
* PROJECT: ReactOS CRT
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Implementation of frexp
5+
* COPYRIGHT: Imported from musl libc
6+
* https://git.musl-libc.org/cgit/musl/tree/src/math/frexp.c
7+
* blob: 27b6266ed0c1d7c5dadd06ecc186a994fdcd1c52
8+
* See https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
79
*/
8-
double
9-
frexp(double __x, int *exptr)
10-
{
11-
union
12-
{
13-
double* __x;
14-
double_s* x;
15-
} x;
16-
17-
x.__x = &__x;
18-
19-
if ( exptr != NULL )
20-
*exptr = x.x->exponent - 0x3FE;
21-
2210

23-
x.x->exponent = 0x3FE;
11+
#include <math.h>
12+
#include <stdint.h>
2413

25-
return __x;
14+
double frexp(double x, int *e)
15+
{
16+
union { double d; uint64_t i; } y = { x };
17+
int ee = y.i>>52 & 0x7ff;
18+
19+
if (!ee) {
20+
if (x) {
21+
x = frexp(x*0x1p64, e);
22+
*e -= 64;
23+
} else *e = 0;
24+
return x;
25+
} else if (ee == 0x7ff) {
26+
return x;
27+
}
28+
29+
*e = ee - 0x3fe;
30+
y.i &= 0x800fffffffffffffull;
31+
y.i |= 0x3fe0000000000000ull;
32+
return y.d;
2633
}
27-
28-
29-

0 commit comments

Comments
 (0)