Mercurial > nand-ecoscentric
comparison packages/language/c/libm/current/src/double/portable-api/s_scalbn.c @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 //=========================================================================== | |
| 2 // | |
| 3 // s_scalbn.c | |
| 4 // | |
| 5 // Part of the standard mathematical function library | |
| 6 // | |
| 7 //=========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //=========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): jlarmour@cygnus.co.uk | |
| 33 // Contributors: jlarmour@cygnus.co.uk | |
| 34 // Date: 1998-02-13 | |
| 35 // Purpose: | |
| 36 // Description: | |
| 37 // Usage: | |
| 38 // | |
| 39 //####DESCRIPTIONEND#### | |
| 40 // | |
| 41 //=========================================================================== | |
| 42 | |
| 43 // CONFIGURATION | |
| 44 | |
| 45 #include <pkgconf/libm.h> // Configuration header | |
| 46 | |
| 47 // Include the Math library? | |
| 48 #ifdef CYGPKG_LIBM | |
| 49 | |
| 50 // Derived from code with the following copyright | |
| 51 | |
| 52 | |
| 53 /* @(#)s_scalbn.c 1.3 95/01/18 */ | |
| 54 /* | |
| 55 * ==================================================== | |
| 56 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
| 57 * | |
| 58 * Developed at SunSoft, a Sun Microsystems, Inc. business. | |
| 59 * Permission to use, copy, modify, and distribute this | |
| 60 * software is freely granted, provided that this notice | |
| 61 * is preserved. | |
| 62 * ==================================================== | |
| 63 */ | |
| 64 | |
| 65 /* | |
| 66 * scalbn (double x, int n) | |
| 67 * scalbn(x,n) returns x* 2**n computed by exponent | |
| 68 * manipulation rather than by actually performing an | |
| 69 * exponentiation or a multiplication. | |
| 70 */ | |
| 71 | |
| 72 #include "mathincl/fdlibm.h" | |
| 73 | |
| 74 static const double | |
| 75 two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ | |
| 76 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ | |
| 77 huge = 1.0e+300, | |
| 78 tiny = 1.0e-300; | |
| 79 | |
| 80 double scalbn (double x, int n) | |
| 81 { | |
| 82 int k,hx,lx; | |
| 83 hx = CYG_LIBM_HI(x); | |
| 84 lx = CYG_LIBM_LO(x); | |
| 85 k = (hx&0x7ff00000)>>20; /* extract exponent */ | |
| 86 if (k==0) { /* 0 or subnormal x */ | |
| 87 if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ | |
| 88 x *= two54; | |
| 89 hx = CYG_LIBM_HI(x); | |
| 90 k = ((hx&0x7ff00000)>>20) - 54; | |
| 91 if (n< -50000) return tiny*x; /*underflow*/ | |
| 92 } | |
| 93 if (k==0x7ff) return x+x; /* NaN or Inf */ | |
| 94 k = k+n; | |
| 95 if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ | |
| 96 if (k > 0) /* normal result */ | |
| 97 {CYG_LIBM_HI(x) = (hx&0x800fffff)|(k<<20); return x;} | |
| 98 if (k <= -54) { | |
| 99 if (n > 50000) /* in case integer overflow in n+k */ | |
| 100 return huge*copysign(huge,x); /*overflow*/ | |
| 101 else return tiny*copysign(tiny,x); /*underflow*/ | |
| 102 } | |
| 103 k += 54; /* subnormal result */ | |
| 104 CYG_LIBM_HI(x) = (hx&0x800fffff)|(k<<20); | |
| 105 return x*twom54; | |
| 106 } | |
| 107 | |
| 108 #endif // ifdef CYGPKG_LIBM | |
| 109 | |
| 110 // EOF s_scalbn.c |
