xref: /netbsd-src/lib/libm/src/w_scalb.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /* @(#)w_scalb.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 #include <sys/cdefs.h>
14 #if defined(LIBM_SCCS) && !defined(lint)
15 __RCSID("$NetBSD: w_scalb.c,v 1.7 1997/10/09 11:36:01 lukem Exp $");
16 #endif
17 
18 /*
19  * wrapper scalb(double x, double fn) is provide for
20  * passing various standard test suite. One
21  * should use scalbn() instead.
22  */
23 
24 #include "math.h"
25 #include "math_private.h"
26 
27 #include <errno.h>
28 
29 #ifdef __STDC__
30 #ifdef _SCALB_INT
31 	double scalb(double x, int fn)		/* wrapper scalb */
32 #else
33 	double scalb(double x, double fn)	/* wrapper scalb */
34 #endif
35 #else
36 	double scalb(x,fn)			/* wrapper scalb */
37 #ifdef _SCALB_INT
38 	double x; int fn;
39 #else
40 	double x,fn;
41 #endif
42 #endif
43 {
44 #ifdef _IEEE_LIBM
45 	return __ieee754_scalb(x,fn);
46 #else
47 	double z;
48 	z = __ieee754_scalb(x,fn);
49 	if(_LIB_VERSION == _IEEE_) return z;
50 	if(!(finite(z)||isnan(z))&&finite(x)) {
51 	    return __kernel_standard(x,(double)fn,32); /* scalb overflow */
52 	}
53 	if(z==0.0&&z!=x) {
54 	    return __kernel_standard(x,(double)fn,33); /* scalb underflow */
55 	}
56 #ifndef _SCALB_INT
57 	if(!finite(fn)) errno = ERANGE;
58 #endif
59 	return z;
60 #endif
61 }
62