xref: /netbsd-src/lib/libm/src/w_scalb.c (revision d9158b13b5dfe46201430699a3f7a235ecf28df3)
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 #ifndef lint
14 static char rcsid[] = "$Id: w_scalb.c,v 1.3 1994/02/18 02:28:05 jtc Exp $";
15 #endif
16 
17 /*
18  * wrapper scalb(double x, double fn) is provide for
19  * passing various standard test suite. One
20  * should use scalbn() instead.
21  */
22 
23 #include <math.h>
24 
25 #include <errno.h>
26 
27 #ifdef __STDC__
28 #ifdef _SCALB_INT
29 	double scalb(double x, int fn)		/* wrapper scalb */
30 #else
31 	double scalb(double x, double fn)	/* wrapper scalb */
32 #endif
33 #else
34 	double scalb(x,fn)			/* wrapper scalb */
35 #ifdef _SCALB_INT
36 	double x; int fn;
37 #else
38 	double x,fn;
39 #endif
40 #endif
41 {
42 #ifdef _IEEE_LIBM
43 	return __ieee754_scalb(x,fn);
44 #else
45 	double z;
46 	z = __ieee754_scalb(x,fn);
47 	if(_LIB_VERSION == _IEEE_) return z;
48 	if(!(finite(z)||isnan(z))&&finite(x)) {
49 	    return __kernel_standard(x,(double)fn,32); /* scalb overflow */
50 	}
51 	if(z==0.0&&z!=x) {
52 	    return __kernel_standard(x,(double)fn,33); /* scalb underflow */
53 	}
54 #ifndef _SCALB_INT
55 	if(!finite(fn)) errno = ERANGE;
56 #endif
57 	return z;
58 #endif
59 }
60