Reactos

[CRT:MATH] Import frexp from musl

+26 -22
+26 -22
sdk/lib/crt/math/frexp.c
··· 1 - #include <math.h> 2 - #include <stdlib.h> 3 - #include <internal/ieee.h> 4 - 5 1 /* 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 7 9 */ 8 - double 9 - frexp(double __x, int *exptr) 10 - { 11 - union 12 - { 13 - double* __x; 14 - double_s* x; 15 - } x; 16 10 17 - x.__x = &__x; 18 - 19 - if ( exptr != NULL ) 20 - *exptr = x.x->exponent - 0x3FE; 11 + #include <math.h> 12 + #include <stdint.h> 21 13 14 + double frexp(double x, int *e) 15 + { 16 + union { double d; uint64_t i; } y = { x }; 17 + int ee = y.i>>52 & 0x7ff; 22 18 23 - x.x->exponent = 0x3FE; 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 + } 24 28 25 - return __x; 29 + *e = ee - 0x3fe; 30 + y.i &= 0x800fffffffffffffull; 31 + y.i |= 0x3fe0000000000000ull; 32 + return y.d; 26 33 } 27 - 28 - 29 -