1570af302Sopenharmony_ci/* origin: FreeBSD /usr/src/lib/msun/src/e_scalbf.c */
2570af302Sopenharmony_ci/*
3570af302Sopenharmony_ci * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4570af302Sopenharmony_ci */
5570af302Sopenharmony_ci/*
6570af302Sopenharmony_ci * ====================================================
7570af302Sopenharmony_ci * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8570af302Sopenharmony_ci *
9570af302Sopenharmony_ci * Developed at SunPro, a Sun Microsystems, Inc. business.
10570af302Sopenharmony_ci * Permission to use, copy, modify, and distribute this
11570af302Sopenharmony_ci * software is freely granted, provided that this notice
12570af302Sopenharmony_ci * is preserved.
13570af302Sopenharmony_ci * ====================================================
14570af302Sopenharmony_ci */
15570af302Sopenharmony_ci
16570af302Sopenharmony_ci#define _GNU_SOURCE
17570af302Sopenharmony_ci#include <math.h>
18570af302Sopenharmony_ci
19570af302Sopenharmony_cifloat scalbf(float x, float fn)
20570af302Sopenharmony_ci{
21570af302Sopenharmony_ci	if (isnan(x) || isnan(fn)) return x*fn;
22570af302Sopenharmony_ci	if (!isfinite(fn)) {
23570af302Sopenharmony_ci		if (fn > 0.0f)
24570af302Sopenharmony_ci			return x*fn;
25570af302Sopenharmony_ci		else
26570af302Sopenharmony_ci			return x/(-fn);
27570af302Sopenharmony_ci	}
28570af302Sopenharmony_ci	if (rintf(fn) != fn) return (fn-fn)/(fn-fn);
29570af302Sopenharmony_ci	if ( fn > 65000.0f) return scalbnf(x, 65000);
30570af302Sopenharmony_ci	if (-fn > 65000.0f) return scalbnf(x,-65000);
31570af302Sopenharmony_ci	return scalbnf(x,(int)fn);
32570af302Sopenharmony_ci}
33