blob: 84a68939b83684b23828a9b5112d203e34a64478 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001
2/* @(#)e_scalb.c 1.3 95/01/18 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
Elliott Hughesa0ee0782013-01-30 19:06:37 -080014#include <sys/cdefs.h>
15__FBSDID("$FreeBSD$");
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080016
17/*
Elliott Hughes4088e3a2023-08-03 13:33:56 -070018 * scalb(x, fn) is provide for
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080019 * passing various standard test suite. One
20 * should use scalbn() instead.
21 */
22
23#include "math.h"
24#include "math_private.h"
25
26#ifdef _SCALB_INT
27double
Elliott Hughes4088e3a2023-08-03 13:33:56 -070028scalb(double x, int fn)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#else
30double
Elliott Hughes4088e3a2023-08-03 13:33:56 -070031scalb(double x, double fn)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080032#endif
33{
34#ifdef _SCALB_INT
35 return scalbn(x,fn);
36#else
37 if (isnan(x)||isnan(fn)) return x*fn;
38 if (!finite(fn)) {
39 if(fn>0.0) return x*fn;
40 else return x/(-fn);
41 }
42 if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
43 if ( fn > 65000.0) return scalbn(x, 65000);
44 if (-fn > 65000.0) return scalbn(x,-65000);
45 return scalbn(x,(int)fn);
46#endif
47}