134438Sbostic/* 234438Sbostic * Copyright (c) 1988 Regents of the University of California. 334438Sbostic * All rights reserved. 434438Sbostic * 534824Sbostic * Redistribution and use in source and binary forms are permitted 634824Sbostic * provided that the above copyright notice and this paragraph are 734824Sbostic * duplicated in all such forms and that any documentation, 834824Sbostic * advertising materials, and other materials related to such 934824Sbostic * distribution and use acknowledge that the software was developed 1034824Sbostic * by the University of California, Berkeley. The name of the 1134824Sbostic * University may not be used to endorse or promote products derived 1234824Sbostic * from this software without specific prior written permission. 1334824Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434824Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534824Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634824Sbostic * 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*42188Sbostic .asciz "@(#)ldexp.s 5.1 (Berkeley) 05/17/90" 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 */ 41*42188Sbostic 42*42188Sbostic/* 43*42188Sbostic * we can't include errno.h anymore, ANSI says that it defines errno. 44*42188Sbostic * 45*42188Sbostic * #include <errno.h> 46*42188Sbostic */ 47*42188Sbostic#define ERANGE 34 4829696Ssam#include <tahoemath/fp.h> 4929696Ssam 5029696Ssam#include "DEFS.h" 5129696Ssam 5229696SsamENTRY(ldexp, 0) 5329696Ssam movl 4(fp),r0 /* Fetch "value" */ 5429696Ssam movl 8(fp),r1 5529696Ssam 5629696Ssam andl3 $EXPMASK,r0,r2 /* r2 := shifted biased exponent */ 5729696Ssam jeql ld1 /* If it's zero, we're done */ 5829696Ssam shar $EXPSHIFT,r2,r2 /* shift to get value of exponent */ 5929696Ssam 6029696Ssam addl2 12(fp),r2 /* r2 := new biased exponent */ 6129696Ssam jleq under /* if it's <= 0, we have an underflow */ 6229696Ssam cmpl r2,$256 /* Otherwise check if it's too big */ 6329696Ssam jgeq over /* jump if overflow */ 6429696Ssam/* 6529696Ssam* Construct the result and return 6629696Ssam*/ 6729696Ssam andl2 $0!EXPMASK,r0 /* clear old exponent */ 6829696Ssam shal $EXPSHIFT,r2,r2 /* Put the exponent back in the result */ 6929696Ssam orl2 r2,r0 7029696Ssamld1: ret 7129696Ssam/* 7229696Ssam* Underflow 7329696Ssam*/ 7429696Ssamunder: clrl r0 /* Result is zero */ 7529696Ssam clrl r1 7629696Ssam jbr err /* Join general error code */ 7729696Ssam/* 7829696Ssam* Overflow 7929696Ssam*/ 8029696Ssamover: movl huge0,r0 /* Largest possible floating magnitude */ 8129696Ssam movl huge1,r1 8229696Ssam jbc $31,4(fp),err /* Jump if argument was positive */ 8329696Ssam orl2 $SIGNBIT,r0 /* If arg < 0, make result negative */ 8429696Ssam 8529696Ssamerr: movl $ERANGE,_errno /* Indicate range error */ 8629696Ssam ret 8729696Ssam 8829696Ssam .data 8929696Ssam .globl _errno /* error flag */ 9029696Ssamhuge0: .word 0x7fff /* The largest number that can */ 9129696Ssam .word 0xffff /* be represented in a long floating */ 9229696Ssamhuge1: .word 0xffff /* number. */ 9329696Ssam .word 0xffff 94