xref: /original-bsd/lib/libc/i386/gen/ldexp.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Sean Eric Fagan.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)ldexp.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 /*
16  * ldexp(value, exp): return value * (2 ** exp).
17  *
18  * Written by Sean Eric Fagan (sef@kithrup.COM)
19  * Sun Mar 11 20:27:09 PST 1990
20  */
21 
22 /*
23  * We do the conversion in C to let gcc optimize it away, if possible.
24  * The "fxch ; fstp" stuff is because value is still on the stack
25  * (stupid 8087!).
26  */
27 double
28 ldexp (double value, int exp)
29 {
30 	double temp, texp, temp2;
31 	texp = exp;
32 	asm ("fscale ; fxch %%st(1) ; fstp%L1 %1 "
33 		: "=f" (temp), "=0" (temp2)
34 		: "0" (texp), "f" (value));
35 	return (temp);
36 }
37