tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[CRT:MATH] Import frexp from musl
Timo Kreuzer
9 months ago
c507b701
b734e3ba
+26
-22
1 changed file
expand all
collapse all
unified
split
sdk
lib
crt
math
frexp.c
+26
-22
sdk/lib/crt/math/frexp.c
···
1
1
-
#include <math.h>
2
2
-
#include <stdlib.h>
3
3
-
#include <internal/ieee.h>
4
4
-
5
1
/*
6
6
-
* @implemented
2
2
+
* PROJECT: ReactOS CRT
3
3
+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4
4
+
* PURPOSE: Implementation of frexp
5
5
+
* COPYRIGHT: Imported from musl libc
6
6
+
* https://git.musl-libc.org/cgit/musl/tree/src/math/frexp.c
7
7
+
* blob: 27b6266ed0c1d7c5dadd06ecc186a994fdcd1c52
8
8
+
* See https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
7
9
*/
8
8
-
double
9
9
-
frexp(double __x, int *exptr)
10
10
-
{
11
11
-
union
12
12
-
{
13
13
-
double* __x;
14
14
-
double_s* x;
15
15
-
} x;
16
10
17
17
-
x.__x = &__x;
18
18
-
19
19
-
if ( exptr != NULL )
20
20
-
*exptr = x.x->exponent - 0x3FE;
11
11
+
#include <math.h>
12
12
+
#include <stdint.h>
21
13
14
14
+
double frexp(double x, int *e)
15
15
+
{
16
16
+
union { double d; uint64_t i; } y = { x };
17
17
+
int ee = y.i>>52 & 0x7ff;
22
18
23
23
-
x.x->exponent = 0x3FE;
19
19
+
if (!ee) {
20
20
+
if (x) {
21
21
+
x = frexp(x*0x1p64, e);
22
22
+
*e -= 64;
23
23
+
} else *e = 0;
24
24
+
return x;
25
25
+
} else if (ee == 0x7ff) {
26
26
+
return x;
27
27
+
}
24
28
25
25
-
return __x;
29
29
+
*e = ee - 0x3fe;
30
30
+
y.i &= 0x800fffffffffffffull;
31
31
+
y.i |= 0x3fe0000000000000ull;
32
32
+
return y.d;
26
33
}
27
27
-
28
28
-
29
29
-