Changeset View
Changeset View
Standalone View
Standalone View
lib/msun/src/s_scalbnl.c
/* @(#)s_scalbn.c 5.1 93/09/24 */ | #include <math.h> | ||||
#include <float.h> | |||||
#include "math_private.h" | |||||
#include "fpmath.h" | |||||
/* | /* | ||||
* ==================================================== | |||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |||||
* | |||||
* Developed at SunPro, a Sun Microsystems, Inc. business. | |||||
* Permission to use, copy, modify, and distribute this | |||||
* software is freely granted, provided that this notice | |||||
* is preserved. | |||||
* ==================================================== | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
/* | |||||
* scalbnl (long double x, int n) | * scalbnl (long double x, int n) | ||||
* scalbnl(x,n) returns x* 2**n computed by exponent | * scalbnl(x,n) returns x* 2**n computed by exponent | ||||
* manipulation rather than by actually performing an | * manipulation rather than by actually performing an | ||||
* exponentiation or a multiplication. | * exponentiation or a multiplication. | ||||
*/ | */ | ||||
/* | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||||
* We assume that a long double has a 15-bit exponent. On systems | long double scalbnl(long double x, int n) | ||||
* where long double is the same as double, scalbnl() is an alias | |||||
* for scalbn(), so we don't use this routine. | |||||
*/ | |||||
#include <float.h> | |||||
#include <math.h> | |||||
#include "fpmath.h" | |||||
#if LDBL_MAX_EXP != 0x4000 | |||||
#error "Unsupported long double format" | |||||
#endif | |||||
static const long double | |||||
huge = 0x1p16000L, | |||||
tiny = 0x1p-16000L; | |||||
long double | |||||
scalbnl (long double x, int n) | |||||
{ | { | ||||
return scalbn(x, n); | |||||
} | |||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | |||||
long double scalbnl(long double x, int n) | |||||
{ | |||||
union IEEEl2bits u; | union IEEEl2bits u; | ||||
int k; | |||||
u.e = x; | if (n > 16383) { | ||||
k = u.bits.exp; /* extract exponent */ | x *= 0x1p16383L; | ||||
if (k==0) { /* 0 or subnormal x */ | n -= 16383; | ||||
if ((u.bits.manh|u.bits.manl)==0) return x; /* +-0 */ | if (n > 16383) { | ||||
u.e *= 0x1p+128; | x *= 0x1p16383L; | ||||
k = u.bits.exp - 128; | n -= 16383; | ||||
if (n< -50000) return tiny*x; /*underflow*/ | if (n > 16383) | ||||
n = 16383; | |||||
} | } | ||||
if (k==0x7fff) return x+x; /* NaN or Inf */ | } else if (n < -16382) { | ||||
k = k+n; | x *= 0x1p-16382L * 0x1p113L; | ||||
if (k >= 0x7fff) return huge*copysignl(huge,x); /* overflow */ | n += 16382 - 113; | ||||
if (k > 0) /* normal result */ | if (n < -16382) { | ||||
{u.bits.exp = k; return u.e;} | x *= 0x1p-16382L * 0x1p113L; | ||||
if (k <= -128) { | n += 16382 - 113; | ||||
if (n > 50000) /* in case integer overflow in n+k */ | if (n < -16382) | ||||
return huge*copysign(huge,x); /*overflow*/ | n = -16382; | ||||
else | |||||
return tiny*copysign(tiny,x); /*underflow*/ | |||||
} | } | ||||
k += 128; /* subnormal result */ | |||||
u.bits.exp = k; | |||||
return u.e*0x1p-128; | |||||
} | } | ||||
u.e = 1.0; | |||||
u.xbits.expsign = 0x3fff + n; | |||||
return x * u.e; | |||||
} | |||||
#endif | |||||
__strong_reference(scalbnl, ldexpl); | __strong_reference(scalbnl, ldexpl); |