|
|
1.1 root 1: /*
2: * Copyright (c) 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: *
19: * This code is derived from software contributed to Berkeley by
20: * Computer Consoles Inc.
21: */
22:
23: #if defined(LIBC_SCCS) && !defined(lint)
24: .asciz "@(#)ldexp.s 5.2 (Berkeley) 6/1/90"
25: #endif /* LIBC_SCCS and not lint */
26:
27: /*
28: * double ldexp (value, exp)
29: * double value;
30: * int exp;
31: *
32: * Ldexp returns value*2**exp, if that result is in range.
33: * If underflow occurs, it returns zero. If overflow occurs,
34: * it returns a value of appropriate sign and largest
35: * possible magnitude. In case of either overflow or underflow,
36: * the external int "errno" is set to ERANGE. Note that errno is
37: * not modified if no error occurs, so if you intend to test it
38: * after you use ldexp, you had better set it to something
39: * other than ERANGE first (zero is a reasonable value to use).
40: *
41: * Constants
42: */
43:
44: /*
45: * we can't include errno.h anymore, ANSI says that it defines errno.
46: *
47: * #include <errno.h>
48: */
49: #define ERANGE 34
50: #include <tahoemath/fp.h>
51:
52: #include "DEFS.h"
53:
54: ENTRY(ldexp, 0)
55: movl 4(fp),r0 /* Fetch "value" */
56: movl 8(fp),r1
57:
58: andl3 $EXPMASK,r0,r2 /* r2 := shifted biased exponent */
59: jeql ld1 /* If it's zero, we're done */
60: shar $EXPSHIFT,r2,r2 /* shift to get value of exponent */
61:
62: addl2 12(fp),r2 /* r2 := new biased exponent */
63: jleq under /* if it's <= 0, we have an underflow */
64: cmpl r2,$256 /* Otherwise check if it's too big */
65: jgeq over /* jump if overflow */
66: /*
67: * Construct the result and return
68: */
69: andl2 $0!EXPMASK,r0 /* clear old exponent */
70: shal $EXPSHIFT,r2,r2 /* Put the exponent back in the result */
71: orl2 r2,r0
72: ld1: ret
73: /*
74: * Underflow
75: */
76: under: clrl r0 /* Result is zero */
77: clrl r1
78: jbr err /* Join general error code */
79: /*
80: * Overflow
81: */
82: over: movl huge0,r0 /* Largest possible floating magnitude */
83: movl huge1,r1
84: jbc $31,4(fp),err /* Jump if argument was positive */
85: orl2 $SIGNBIT,r0 /* If arg < 0, make result negative */
86:
87: err: movl $ERANGE,_errno /* Indicate range error */
88: ret
89:
90: .data
91: .globl _errno /* error flag */
92: huge0: .word 0x7fff /* The largest number that can */
93: .word 0xffff /* be represented in a long floating */
94: huge1: .word 0xffff /* number. */
95: .word 0xffff
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.