Back to index

glibc  2.9
e_scalb.c
Go to the documentation of this file.
00001 /* @(#)e_scalb.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice
00009  * is preserved.
00010  * ====================================================
00011  */
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: e_scalb.c,v 1.6 1995/05/10 20:46:09 jtc Exp $";
00015 #endif
00016 
00017 /*
00018  * __ieee754_scalb(x, fn) is provide for
00019  * passing various standard test suite. One
00020  * should use scalbn() instead.
00021  */
00022 
00023 #include <fenv.h>
00024 #include <math.h>
00025 #include "math_private.h"
00026 
00027 #ifdef _SCALB_INT
00028 #ifdef __STDC__
00029        double __ieee754_scalb(double x, int fn)
00030 #else
00031        double __ieee754_scalb(x,fn)
00032        double x; int fn;
00033 #endif
00034 #else
00035 #ifdef __STDC__
00036        double __ieee754_scalb(double x, double fn)
00037 #else
00038        double __ieee754_scalb(x,fn)
00039        double x, fn;
00040 #endif
00041 #endif
00042 {
00043 #ifdef _SCALB_INT
00044        return __scalbn(x,fn);
00045 #else
00046        if (__isnan(x)||__isnan(fn)) return x*fn;
00047        if (!__finite(fn)) {
00048            if(fn>0.0) return x*fn;
00049            else if (x == 0)
00050              return x;
00051            else if (!__finite (x))
00052              {
00053 # ifdef FE_INVALID
00054               feraiseexcept (FE_INVALID);
00055 # endif
00056               return __nan ("");
00057              }
00058            else       return x/(-fn);
00059        }
00060        if (__rint(fn)!=fn)
00061          {
00062 # ifdef FE_INVALID
00063            feraiseexcept (FE_INVALID);
00064 # endif
00065            return __nan ("");
00066          }
00067        if ( fn > 65000.0) return __scalbn(x, 65000);
00068        if (-fn > 65000.0) return __scalbn(x,-65000);
00069        return __scalbn(x,(int)fn);
00070 #endif
00071 }