13a8617a8SJordan K. Hubbard /* @(#)s_frexp.c 5.1 93/09/24 */ 23a8617a8SJordan K. Hubbard /* 33a8617a8SJordan K. Hubbard * ==================================================== 43a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 53a8617a8SJordan K. Hubbard * 63a8617a8SJordan K. Hubbard * Developed at SunPro, a Sun Microsystems, Inc. business. 73a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this 83a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice 93a8617a8SJordan K. Hubbard * is preserved. 103a8617a8SJordan K. Hubbard * ==================================================== 113a8617a8SJordan K. Hubbard */ 123a8617a8SJordan K. Hubbard 133a8617a8SJordan K. Hubbard #ifndef lint 147f3dea24SPeter Wemm static char rcsid[] = "$FreeBSD$"; 153a8617a8SJordan K. Hubbard #endif 163a8617a8SJordan K. Hubbard 173a8617a8SJordan K. Hubbard /* 183a8617a8SJordan K. Hubbard * for non-zero x 193a8617a8SJordan K. Hubbard * x = frexp(arg,&exp); 203a8617a8SJordan K. Hubbard * return a double fp quantity x such that 0.5 <= |x| <1.0 213a8617a8SJordan K. Hubbard * and the corresponding binary exponent "exp". That is 223a8617a8SJordan K. Hubbard * arg = x*2^exp. 233a8617a8SJordan K. Hubbard * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg 243a8617a8SJordan K. Hubbard * with *exp=0. 253a8617a8SJordan K. Hubbard */ 263a8617a8SJordan K. Hubbard 27f8a40fcaSDavid Schultz #include <sys/cdefs.h> 28f8a40fcaSDavid Schultz #include <float.h> 29f8a40fcaSDavid Schultz 303a8617a8SJordan K. Hubbard #include "math.h" 313a8617a8SJordan K. Hubbard #include "math_private.h" 323a8617a8SJordan K. Hubbard 333a8617a8SJordan K. Hubbard static const double 343a8617a8SJordan K. Hubbard two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ 353a8617a8SJordan K. Hubbard 3659b19ff1SAlfred Perlstein double 3759b19ff1SAlfred Perlstein frexp(double x, int *eptr) 383a8617a8SJordan K. Hubbard { 393a8617a8SJordan K. Hubbard int32_t hx, ix, lx; 403a8617a8SJordan K. Hubbard EXTRACT_WORDS(hx,lx,x); 413a8617a8SJordan K. Hubbard ix = 0x7fffffff&hx; 423a8617a8SJordan K. Hubbard *eptr = 0; 433a8617a8SJordan K. Hubbard if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ 443a8617a8SJordan K. Hubbard if (ix<0x00100000) { /* subnormal */ 453a8617a8SJordan K. Hubbard x *= two54; 463a8617a8SJordan K. Hubbard GET_HIGH_WORD(hx,x); 473a8617a8SJordan K. Hubbard ix = hx&0x7fffffff; 483a8617a8SJordan K. Hubbard *eptr = -54; 493a8617a8SJordan K. Hubbard } 503a8617a8SJordan K. Hubbard *eptr += (ix>>20)-1022; 513a8617a8SJordan K. Hubbard hx = (hx&0x800fffff)|0x3fe00000; 523a8617a8SJordan K. Hubbard SET_HIGH_WORD(x,hx); 533a8617a8SJordan K. Hubbard return x; 543a8617a8SJordan K. Hubbard } 55f8a40fcaSDavid Schultz 56f8a40fcaSDavid Schultz #if (LDBL_MANT_DIG == 53) 573d266bdeSDavid Schultz __weak_reference(frexp, frexpl); 58f8a40fcaSDavid Schultz #endif 59