1570af302Sopenharmony_ci/* origin: FreeBSD /usr/src/lib/msun/src/e_scalb.c */
2570af302Sopenharmony_ci/*
3570af302Sopenharmony_ci * ====================================================
4570af302Sopenharmony_ci * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5570af302Sopenharmony_ci *
6570af302Sopenharmony_ci * Developed at SunSoft, a Sun Microsystems, Inc. business.
7570af302Sopenharmony_ci * Permission to use, copy, modify, and distribute this
8570af302Sopenharmony_ci * software is freely granted, provided that this notice
9570af302Sopenharmony_ci * is preserved.
10570af302Sopenharmony_ci * ====================================================
11570af302Sopenharmony_ci */
12570af302Sopenharmony_ci/*
13570af302Sopenharmony_ci * scalb(x, fn) is provide for
14570af302Sopenharmony_ci * passing various standard test suite. One
15570af302Sopenharmony_ci * should use scalbn() instead.
16570af302Sopenharmony_ci */
17570af302Sopenharmony_ci
18570af302Sopenharmony_ci#define _GNU_SOURCE
19570af302Sopenharmony_ci#include <math.h>
20570af302Sopenharmony_ci
21570af302Sopenharmony_cidouble scalb(double x, double fn)
22570af302Sopenharmony_ci{
23570af302Sopenharmony_ci	if (isnan(x) || isnan(fn))
24570af302Sopenharmony_ci		return x*fn;
25570af302Sopenharmony_ci	if (!isfinite(fn)) {
26570af302Sopenharmony_ci		if (fn > 0.0)
27570af302Sopenharmony_ci			return x*fn;
28570af302Sopenharmony_ci		else
29570af302Sopenharmony_ci			return x/(-fn);
30570af302Sopenharmony_ci	}
31570af302Sopenharmony_ci	if (rint(fn) != fn) return (fn-fn)/(fn-fn);
32570af302Sopenharmony_ci	if ( fn > 65000.0) return scalbn(x, 65000);
33570af302Sopenharmony_ci	if (-fn > 65000.0) return scalbn(x,-65000);
34570af302Sopenharmony_ci	return scalbn(x,(int)fn);
35570af302Sopenharmony_ci}
36