xref: /netbsd-src/lib/libm/src/e_scalb.c (revision d4def06880b057e77ee86e4a4a3f87e29850fb1d)
113618394Sjtc /* @(#)e_scalb.c 5.1 93/09/24 */
213618394Sjtc /*
313618394Sjtc  * ====================================================
413618394Sjtc  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
513618394Sjtc  *
613618394Sjtc  * Developed at SunPro, a Sun Microsystems, Inc. business.
713618394Sjtc  * Permission to use, copy, modify, and distribute this
813618394Sjtc  * software is freely granted, provided that this notice
913618394Sjtc  * is preserved.
1013618394Sjtc  * ====================================================
1113618394Sjtc  */
1213618394Sjtc 
13dd7adfbfSlukem #include <sys/cdefs.h>
14d1f06e0bSjtc #if defined(LIBM_SCCS) && !defined(lint)
15*d4def068Sdrochner __RCSID("$NetBSD: e_scalb.c,v 1.10 2010/04/23 19:17:07 drochner Exp $");
16bc3f7bf6Sjtc #endif
17bc3f7bf6Sjtc 
1813618394Sjtc /*
1913618394Sjtc  * __ieee754_scalb(x, fn) is provide for
2013618394Sjtc  * passing various standard test suite. One
2113618394Sjtc  * should use scalbn() instead.
2213618394Sjtc  */
2313618394Sjtc 
24*d4def068Sdrochner #include "namespace.h"
258346e333Sjtc #include "math.h"
268346e333Sjtc #include "math_private.h"
2713618394Sjtc 
2813618394Sjtc #ifdef _SCALB_INT
29aa30599eSwiz double
__ieee754_scalb(double x,int fn)30aa30599eSwiz __ieee754_scalb(double x, int fn)
3113618394Sjtc #else
32aa30599eSwiz double
33aa30599eSwiz __ieee754_scalb(double x, double fn)
3413618394Sjtc #endif
3513618394Sjtc {
3613618394Sjtc #ifdef _SCALB_INT
3713618394Sjtc 	return scalbn(x,fn);
3813618394Sjtc #else
3913618394Sjtc 	if (isnan(x)||isnan(fn)) return x*fn;
4013618394Sjtc 	if (!finite(fn)) {
4113618394Sjtc 	    if(fn>0.0) return x*fn;
4213618394Sjtc 	    else       return x/(-fn);
4313618394Sjtc 	}
4413618394Sjtc 	if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
4513618394Sjtc 	if ( fn > 65000.0) return scalbn(x, 65000);
4613618394Sjtc 	if (-fn > 65000.0) return scalbn(x,-65000);
4713618394Sjtc 	return scalbn(x,(int)fn);
4813618394Sjtc #endif
4913618394Sjtc }
50