xref: /netbsd/lib/libm/src/e_scalbf.c (revision d4def068)
18346e333Sjtc /* e_scalbf.c -- float version of e_scalb.c.
28346e333Sjtc  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
38346e333Sjtc  */
48346e333Sjtc 
58346e333Sjtc /*
68346e333Sjtc  * ====================================================
78346e333Sjtc  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
88346e333Sjtc  *
98346e333Sjtc  * Developed at SunPro, a Sun Microsystems, Inc. business.
108346e333Sjtc  * Permission to use, copy, modify, and distribute this
118346e333Sjtc  * software is freely granted, provided that this notice
128346e333Sjtc  * is preserved.
138346e333Sjtc  * ====================================================
148346e333Sjtc  */
158346e333Sjtc 
16dd7adfbfSlukem #include <sys/cdefs.h>
17d1f06e0bSjtc #if defined(LIBM_SCCS) && !defined(lint)
18*d4def068Sdrochner __RCSID("$NetBSD: e_scalbf.c,v 1.7 2010/04/23 19:17:07 drochner Exp $");
198346e333Sjtc #endif
208346e333Sjtc 
21*d4def068Sdrochner #include "namespace.h"
228346e333Sjtc #include "math.h"
238346e333Sjtc #include "math_private.h"
248346e333Sjtc 
258346e333Sjtc #ifdef _SCALB_INT
26aa30599eSwiz float
__ieee754_scalbf(float x,int fn)27aa30599eSwiz __ieee754_scalbf(float x, int fn)
288346e333Sjtc #else
29aa30599eSwiz float
30aa30599eSwiz __ieee754_scalbf(float x, float fn)
318346e333Sjtc #endif
328346e333Sjtc {
338346e333Sjtc #ifdef _SCALB_INT
348346e333Sjtc 	return scalbnf(x,fn);
358346e333Sjtc #else
368346e333Sjtc 	if (isnanf(x)||isnanf(fn)) return x*fn;
378346e333Sjtc 	if (!finitef(fn)) {
388346e333Sjtc 	    if(fn>(float)0.0) return x*fn;
398346e333Sjtc 	    else       return x/(-fn);
408346e333Sjtc 	}
418346e333Sjtc 	if (rintf(fn)!=fn) return (fn-fn)/(fn-fn);
428346e333Sjtc 	if ( fn > (float)65000.0) return scalbnf(x, 65000);
438346e333Sjtc 	if (-fn > (float)65000.0) return scalbnf(x,-65000);
448346e333Sjtc 	return scalbnf(x,(int)fn);
458346e333Sjtc #endif
468346e333Sjtc }
47