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