1*34438Sbostic/* 2*34438Sbostic * Copyright (c) 1988 Regents of the University of California. 3*34438Sbostic * All rights reserved. 4*34438Sbostic * 5*34438Sbostic * This code is derived from software contributed to Berkeley by 6*34438Sbostic * Computer Consoles Inc. 7*34438Sbostic * 8*34438Sbostic * Redistribution and use in source and binary forms are permitted 9*34438Sbostic * provided that this notice is preserved and that due credit is given 10*34438Sbostic * to the University of California at Berkeley. The name of the University 11*34438Sbostic * may not be used to endorse or promote products derived from this 12*34438Sbostic * software without specific prior written permission. This software 13*34438Sbostic * is provided ``as is'' without express or implied warranty. 14*34438Sbostic */ 1529696Ssam 16*34438Sbostic#if defined(LIBC_SCCS) && !defined(lint) 17*34438Sbostic_sccsid:.asciz "@(#)modf.s 1.3 (Berkeley) 05/23/88" 18*34438Sbostic#endif /* LIBC_SCCS and not lint */ 19*34438Sbostic 2029696Ssam/* 2129696Ssam * double modf (value, iptr) 2229696Ssam * double value, *iptr; 2329696Ssam * 2429696Ssam * Modf returns the fractional part of "value", 2529696Ssam * and stores the integer part indirectly through "iptr". 2629696Ssam * 2729696Ssam * This version uses floating point (look in ../fpe for 2829696Ssam * a much slower integer version). 2929696Ssam */ 3029696Ssam 3129696Ssam#include "DEFS.h" 3229696Ssam 3329696SsamENTRY(modf, 0) 3430512Ssam ldd 4(fp) # value 3530512Ssam cvdl r2 # integerize 3630512Ssam bvs 1f # did integer part overflow? 3730512Ssam cvld r2 # integer part 3830512Ssam std r0 3930512Ssam std *12(fp) # *iptr = r2 4029696Ssam ldd 4(fp) 4130512Ssam subd r0 # value-(int)value 4230512Ssam std r0 # return fraction 4329696Ssam ret 4429696Ssam1: 4530512Ssam /* 4630512Ssam * If the integer portion overflowed, mask out the fractional 4730512Ssam * bits in the double word instead of cvdl-ing. 4830512Ssam */ 4929696Ssam ldd 4(fp) 5030512Ssam std r0 # (r0,r1) = value 5130512Ssam shrl $23,r0,r2 # extract sign,exponent of value 5230512Ssam andl2 $255,r2 # exponent 5330512Ssam subl2 $152,r2 # e-152 5430512Ssam /* 5530512Ssam * If it overflowed then value>=2^31 and e>=160 5630512Ssam * so we mask only r1 (low bits of fraction), not r0 5730512Ssam */ 5830512Ssam mnegl $1,r3 5930512Ssam shrl r2,r3,r3 # -1>>(e-152) is neg mask to clear fraction 6030512Ssam mcoml r3,r3 # complement mask 6130512Ssam andl2 r3,r1 # mask off truly fractional bits from fraction 6230512Ssam ldd r0 # now (r0,r1) = integerized value 6330512Ssam std *12(fp) # *iptr = integerized 6430512Ssam ldd 4(fp) 6529696Ssam subd r0 6630512Ssam std r0 # return fraction 6729696Ssam ret 68