xref: /csrg-svn/lib/libc/vax/gen/ldexp.s (revision 34480)
1*34480Sbostic/*
2*34480Sbostic * Copyright (c) 1983 Regents of the University of California.
3*34480Sbostic * All rights reserved.
4*34480Sbostic *
5*34480Sbostic * Redistribution and use in source and binary forms are permitted
6*34480Sbostic * provided that this notice is preserved and that due credit is given
7*34480Sbostic * to the University of California at Berkeley. The name of the University
8*34480Sbostic * may not be used to endorse or promote products derived from this
9*34480Sbostic * software without specific written prior permission. This software
10*34480Sbostic * is provided ``as is'' without express or implied warranty.
11*34480Sbostic */
1213416Sroot
13*34480Sbostic#if defined(SYSLIBC_SCCS) && !defined(lint)
14*34480Sbostic_sccsid:.asciz	"@(#)ldexp.s	5.3 (Berkeley) 05/25/88"
15*34480Sbostic#endif /* SYSLIBC_SCCS and not lint */
16*34480Sbostic
1713416Sroot/*
1813416Sroot * double ldexp (value, exp)
1913416Sroot * double value;
2013416Sroot * int exp;
2113416Sroot *
2213416Sroot * Ldexp returns value*2**exp, if that result is in range.
2313416Sroot * If underflow occurs, it returns zero.  If overflow occurs,
2413416Sroot * it returns a value of appropriate sign and largest
2513416Sroot * possible magnitude.  In case of either overflow or underflow,
2613416Sroot * errno is set to ERANGE.  Note that errno is not modified if
2713416Sroot * no error occurs.
2813416Sroot */
2913416Sroot
3013416Sroot#include "DEFS.h"
3113416Sroot#include <errno.h>
3213416Sroot
3313416Sroot	.globl	_errno
3413416Sroot
3517329SsamENTRY(ldexp, 0)
3613416Sroot	movd	4(ap),r0	/* fetch "value" */
3713416Sroot	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
3813416Sroot	jeql	1f		/* if zero, done */
3913416Sroot
4013416Sroot	addl2	12(ap),r2	/* r2 := new biased exponent */
4113416Sroot	jleq	2f		/* if <= 0, underflow */
4213416Sroot	cmpl	r2,$256		/* otherwise check if too big */
4313416Sroot	jgeq	3f		/* jump if overflow */
4413416Sroot	insv	r2,$7,$8,r0	/* put exponent back in result */
4513416Sroot1:
4613416Sroot	ret
4713416Sroot2:
4813416Sroot	clrd	r0
4913416Sroot	jbr	1f
5013416Sroot3:
5113416Sroot	movd	huge,r0		/* largest possible floating magnitude */
5213416Sroot	jbc	$15,4(ap),1f	/* jump if argument was positive */
5313416Sroot	mnegd	r0,r0		/* if arg < 0, make result negative */
5413416Sroot1:
5513416Sroot	movl	$ERANGE,_errno
5613416Sroot	ret
5713416Sroot
5813416Sroot	.data
5913416Sroothuge:	.word	0x7fff		/* the largest number that can */
6013416Sroot	.word	0xffff		/*   be represented in a long floating */
6113416Sroot	.word	0xffff		/*   number.  This is given in hex in order */
6213416Sroot	.word	0xffff		/*   to avoid floating conversions */
63