xref: /csrg-svn/lib/libc/vax/gen/ldexp.s (revision 22285)
1#ifndef lint
2	.asciz	"@(#)ldexp.s	5.1 (Berkeley) 06/05/85"
3#endif not lint
4
5/*
6 * double ldexp (value, exp)
7 * double value;
8 * int exp;
9 *
10 * Ldexp returns value*2**exp, if that result is in range.
11 * If underflow occurs, it returns zero.  If overflow occurs,
12 * it returns a value of appropriate sign and largest
13 * possible magnitude.  In case of either overflow or underflow,
14 * errno is set to ERANGE.  Note that errno is not modified if
15 * no error occurs.
16 */
17
18#include "DEFS.h"
19#include <errno.h>
20
21	.globl	_errno
22
23ENTRY(ldexp, 0)
24	movd	4(ap),r0	/* fetch "value" */
25	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
26	jeql	1f		/* if zero, done */
27
28	addl2	12(ap),r2	/* r2 := new biased exponent */
29	jleq	2f		/* if <= 0, underflow */
30	cmpl	r2,$256		/* otherwise check if too big */
31	jgeq	3f		/* jump if overflow */
32	insv	r2,$7,$8,r0	/* put exponent back in result */
331:
34	ret
352:
36	clrd	r0
37	jbr	1f
383:
39	movd	huge,r0		/* largest possible floating magnitude */
40	jbc	$15,4(ap),1f	/* jump if argument was positive */
41	mnegd	r0,r0		/* if arg < 0, make result negative */
421:
43	movl	$ERANGE,_errno
44	ret
45
46	.data
47huge:	.word	0x7fff		/* the largest number that can */
48	.word	0xffff		/*   be represented in a long floating */
49	.word	0xffff		/*   number.  This is given in hex in order */
50	.word	0xffff		/*   to avoid floating conversions */
51