134438Sbostic/* 234438Sbostic * Copyright (c) 1988 Regents of the University of California. 334438Sbostic * All rights reserved. 434438Sbostic * 5*34824Sbostic * Redistribution and use in source and binary forms are permitted 6*34824Sbostic * provided that the above copyright notice and this paragraph are 7*34824Sbostic * duplicated in all such forms and that any documentation, 8*34824Sbostic * advertising materials, and other materials related to such 9*34824Sbostic * distribution and use acknowledge that the software was developed 10*34824Sbostic * by the University of California, Berkeley. The name of the 11*34824Sbostic * University may not be used to endorse or promote products derived 12*34824Sbostic * from this software without specific prior written permission. 13*34824Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34824Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34824Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*34824Sbostic * 1734438Sbostic * This code is derived from software contributed to Berkeley by 1834438Sbostic * Computer Consoles Inc. 1934438Sbostic */ 2029696Ssam 2134438Sbostic#if defined(LIBC_SCCS) && !defined(lint) 22*34824Sbostic .asciz "@(#)ldexp.s 1.3 (Berkeley) 06/27/88" 2334438Sbostic#endif /* LIBC_SCCS and not lint */ 2434438Sbostic 2529696Ssam/* 2629696Ssam * double ldexp (value, exp) 2729696Ssam * double value; 2829696Ssam * int exp; 2929696Ssam * 3029696Ssam * Ldexp returns value*2**exp, if that result is in range. 3129696Ssam * If underflow occurs, it returns zero. If overflow occurs, 3229696Ssam * it returns a value of appropriate sign and largest 3329696Ssam * possible magnitude. In case of either overflow or underflow, 3429696Ssam * the external int "errno" is set to ERANGE. Note that errno is 3529696Ssam * not modified if no error occurs, so if you intend to test it 3629696Ssam * after you use ldexp, you had better set it to something 3729696Ssam * other than ERANGE first (zero is a reasonable value to use). 3829696Ssam * 3929696Ssam * Constants 4029696Ssam */ 4129696Ssam#include <errno.h> 4229696Ssam#include <tahoemath/fp.h> 4329696Ssam 4429696Ssam#include "DEFS.h" 4529696Ssam 4629696SsamENTRY(ldexp, 0) 4729696Ssam movl 4(fp),r0 /* Fetch "value" */ 4829696Ssam movl 8(fp),r1 4929696Ssam 5029696Ssam andl3 $EXPMASK,r0,r2 /* r2 := shifted biased exponent */ 5129696Ssam jeql ld1 /* If it's zero, we're done */ 5229696Ssam shar $EXPSHIFT,r2,r2 /* shift to get value of exponent */ 5329696Ssam 5429696Ssam addl2 12(fp),r2 /* r2 := new biased exponent */ 5529696Ssam jleq under /* if it's <= 0, we have an underflow */ 5629696Ssam cmpl r2,$256 /* Otherwise check if it's too big */ 5729696Ssam jgeq over /* jump if overflow */ 5829696Ssam/* 5929696Ssam* Construct the result and return 6029696Ssam*/ 6129696Ssam andl2 $0!EXPMASK,r0 /* clear old exponent */ 6229696Ssam shal $EXPSHIFT,r2,r2 /* Put the exponent back in the result */ 6329696Ssam orl2 r2,r0 6429696Ssamld1: ret 6529696Ssam/* 6629696Ssam* Underflow 6729696Ssam*/ 6829696Ssamunder: clrl r0 /* Result is zero */ 6929696Ssam clrl r1 7029696Ssam jbr err /* Join general error code */ 7129696Ssam/* 7229696Ssam* Overflow 7329696Ssam*/ 7429696Ssamover: movl huge0,r0 /* Largest possible floating magnitude */ 7529696Ssam movl huge1,r1 7629696Ssam jbc $31,4(fp),err /* Jump if argument was positive */ 7729696Ssam orl2 $SIGNBIT,r0 /* If arg < 0, make result negative */ 7829696Ssam 7929696Ssamerr: movl $ERANGE,_errno /* Indicate range error */ 8029696Ssam ret 8129696Ssam 8229696Ssam .data 8329696Ssam .globl _errno /* error flag */ 8429696Ssamhuge0: .word 0x7fff /* The largest number that can */ 8529696Ssam .word 0xffff /* be represented in a long floating */ 8629696Ssamhuge1: .word 0xffff /* number. */ 8729696Ssam .word 0xffff 88