134480Sbostic/* 234480Sbostic * Copyright (c) 1983 Regents of the University of California. 334480Sbostic * All rights reserved. 434480Sbostic * 534480Sbostic * Redistribution and use in source and binary forms are permitted 6*34819Sbostic * provided that the above copyright notice and this paragraph are 7*34819Sbostic * duplicated in all such forms and that any documentation, 8*34819Sbostic * advertising materials, and other materials related to such 9*34819Sbostic * distribution and use acknowledge that the software was developed 10*34819Sbostic * by the University of California, Berkeley. The name of the 11*34819Sbostic * University may not be used to endorse or promote products derived 12*34819Sbostic * from this software without specific prior written permission. 13*34819Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34819Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34819Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634480Sbostic */ 1713416Sroot 18*34819Sbostic#if defined(LIBC_SCCS) && !defined(lint) 19*34819Sbostic .asciz "@(#)ldexp.s 5.4 (Berkeley) 06/27/88" 20*34819Sbostic#endif /* LIBC_SCCS and not lint */ 2134480Sbostic 2213416Sroot/* 2313416Sroot * double ldexp (value, exp) 2413416Sroot * double value; 2513416Sroot * int exp; 2613416Sroot * 2713416Sroot * Ldexp returns value*2**exp, if that result is in range. 2813416Sroot * If underflow occurs, it returns zero. If overflow occurs, 2913416Sroot * it returns a value of appropriate sign and largest 3013416Sroot * possible magnitude. In case of either overflow or underflow, 3113416Sroot * errno is set to ERANGE. Note that errno is not modified if 3213416Sroot * no error occurs. 3313416Sroot */ 3413416Sroot 3513416Sroot#include "DEFS.h" 3613416Sroot#include <errno.h> 3713416Sroot 3813416Sroot .globl _errno 3913416Sroot 4017329SsamENTRY(ldexp, 0) 4113416Sroot movd 4(ap),r0 /* fetch "value" */ 4213416Sroot extzv $7,$8,r0,r2 /* r2 := biased exponent */ 4313416Sroot jeql 1f /* if zero, done */ 4413416Sroot 4513416Sroot addl2 12(ap),r2 /* r2 := new biased exponent */ 4613416Sroot jleq 2f /* if <= 0, underflow */ 4713416Sroot cmpl r2,$256 /* otherwise check if too big */ 4813416Sroot jgeq 3f /* jump if overflow */ 4913416Sroot insv r2,$7,$8,r0 /* put exponent back in result */ 5013416Sroot1: 5113416Sroot ret 5213416Sroot2: 5313416Sroot clrd r0 5413416Sroot jbr 1f 5513416Sroot3: 5613416Sroot movd huge,r0 /* largest possible floating magnitude */ 5713416Sroot jbc $15,4(ap),1f /* jump if argument was positive */ 5813416Sroot mnegd r0,r0 /* if arg < 0, make result negative */ 5913416Sroot1: 6013416Sroot movl $ERANGE,_errno 6113416Sroot ret 6213416Sroot 6313416Sroot .data 6413416Sroothuge: .word 0x7fff /* the largest number that can */ 6513416Sroot .word 0xffff /* be represented in a long floating */ 6613416Sroot .word 0xffff /* number. This is given in hex in order */ 6713416Sroot .word 0xffff /* to avoid floating conversions */ 68