1 /* 2 * This file is part of the MicroPython project, http://micropython.org/ 3 * 4 * These math functions are taken from newlib-nano-2, the newlib/libm/math 5 * directory, available from https://github.com/32bitmicro/newlib-nano-2. 6 * 7 * Appropriate copyright headers are reproduced below. 8 */ 9 10 /* sf_frexp.c -- float version of s_frexp.c. 11 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 12 */ 13 14 /* 15 * ==================================================== 16 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 17 * 18 * Developed at SunPro, a Sun Microsystems, Inc. business. 19 * Permission to use, copy, modify, and distribute this 20 * software is freely granted, provided that this notice 21 * is preserved. 22 * ==================================================== 23 */ 24 25 #include "fdlibm.h" 26 27 #ifdef __STDC__ 28 static const float 29 #else 30 static float 31 #endif 32 two25 = 3.3554432000e+07f; /* 0x4c000000 */ 33 34 #ifdef __STDC__ frexpf(float x,int * eptr)35 float frexpf(float x, int *eptr) 36 #else 37 float frexpf(x, eptr) 38 float x; int *eptr; 39 #endif 40 { 41 __int32_t hx, ix; 42 GET_FLOAT_WORD(hx,x); 43 ix = 0x7fffffff&hx; 44 *eptr = 0; 45 if(!FLT_UWORD_IS_FINITE(ix)||FLT_UWORD_IS_ZERO(ix)) return x; /* 0,inf,nan */ 46 if (FLT_UWORD_IS_SUBNORMAL(ix)) { /* subnormal */ 47 x *= two25; 48 GET_FLOAT_WORD(hx,x); 49 ix = hx&0x7fffffff; 50 *eptr = -25; 51 } 52 *eptr += (ix>>23)-126; 53 hx = (hx&0x807fffff)|0x3f000000; 54 SET_FLOAT_WORD(x,hx); 55 return x; 56 } 57 58 #ifdef _DOUBLE_IS_32BITS 59 60 #ifdef __STDC__ frexp(double x,int * eptr)61 double frexp(double x, int *eptr) 62 #else 63 double frexp(x, eptr) 64 double x; int *eptr; 65 #endif 66 { 67 return (double) frexpf((float) x, eptr); 68 } 69 70 #endif /* defined(_DOUBLE_IS_32BITS) */ 71