xref: /netbsd-src/lib/libm/src/e_scalb.c (revision d9158b13b5dfe46201430699a3f7a235ecf28df3)
1 /* @(#)e_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: e_scalb.c,v 1.3 1994/02/18 02:25:47 jtc Exp $";
15 #endif
16 
17 /*
18  * __ieee754_scalb(x, fn) is provide for
19  * passing various standard test suite. One
20  * should use scalbn() instead.
21  */
22 
23 #include <math.h>
24 
25 #ifdef _SCALB_INT
26 #ifdef __STDC__
27 	double __ieee754_scalb(double x, int fn)
28 #else
29 	double __ieee754_scalb(x,fn)
30 	double x; int fn;
31 #endif
32 #else
33 #ifdef __STDC__
34 	double __ieee754_scalb(double x, double fn)
35 #else
36 	double __ieee754_scalb(x,fn)
37 	double x, fn;
38 #endif
39 #endif
40 {
41 #ifdef _SCALB_INT
42 	return scalbn(x,fn);
43 #else
44 	if (isnan(x)||isnan(fn)) return x*fn;
45 	if (!finite(fn)) {
46 	    if(fn>0.0) return x*fn;
47 	    else       return x/(-fn);
48 	}
49 	if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
50 	if ( fn > 65000.0) return scalbn(x, 65000);
51 	if (-fn > 65000.0) return scalbn(x,-65000);
52 	return scalbn(x,(int)fn);
53 #endif
54 }
55