(no message)
[unix-history] / usr / src / lib / libc / vax / gen / ldexp.s
CommitLineData
73f2cfac
BJ
1/* ldexp.s 4.1 83/06/27 */
2
3/*
4 * double ldexp (value, exp)
5 * double value;
6 * int exp;
7 *
8 * Ldexp returns value*2**exp, if that result is in range.
9 * If underflow occurs, it returns zero. If overflow occurs,
10 * it returns a value of appropriate sign and largest
11 * possible magnitude. In case of either overflow or underflow,
12 * errno is set to ERANGE. Note that errno is not modified if
13 * no error occurs.
14 */
15
16#include "DEFS.h"
17#include <errno.h>
18
19 .globl _errno
20
21ENTRY(ldexp)
22 movd 4(ap),r0 /* fetch "value" */
23 extzv $7,$8,r0,r2 /* r2 := biased exponent */
24 jeql 1f /* if zero, done */
25
26 addl2 12(ap),r2 /* r2 := new biased exponent */
27 jleq 2f /* if <= 0, underflow */
28 cmpl r2,$256 /* otherwise check if too big */
29 jgeq 3f /* jump if overflow */
30 insv r2,$7,$8,r0 /* put exponent back in result */
311:
32 ret
332:
34 clrd r0
35 jbr 1f
363:
37 movd huge,r0 /* largest possible floating magnitude */
38 jbc $15,4(ap),1f /* jump if argument was positive */
39 mnegd r0,r0 /* if arg < 0, make result negative */
401:
41 movl $ERANGE,_errno
42 ret
43
44 .data
45huge: .word 0x7fff /* the largest number that can */
46 .word 0xffff /* be represented in a long floating */
47 .word 0xffff /* number. This is given in hex in order */
48 .word 0xffff /* to avoid floating conversions */