1/* 2 * Copyright (c) 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Computer Consoles Inc. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11#if defined(LIBC_SCCS) && !defined(lint) 12 .asciz "@(#)modf.s 5.1 (Berkeley) 01/30/91" 13#endif /* LIBC_SCCS and not lint */ 14 15/* 16 * double modf (value, iptr) 17 * double value, *iptr; 18 * 19 * Modf returns the fractional part of "value", 20 * and stores the integer part indirectly through "iptr". 21 * 22 * This version uses floating point (look in ../fpe for 23 * a much slower integer version). 24 */ 25 26#include "DEFS.h" 27 28ENTRY(modf, 0) 29 ldd 4(fp) # value 30 cvdl r2 # integerize 31 bvs 1f # did integer part overflow? 32 cvld r2 # integer part 33 std r0 34 std *12(fp) # *iptr = r2 35 ldd 4(fp) 36 subd r0 # value-(int)value 37 std r0 # return fraction 38 ret 391: 40 /* 41 * If the integer portion overflowed, mask out the fractional 42 * bits in the double word instead of cvdl-ing. 43 */ 44 ldd 4(fp) 45 std r0 # (r0,r1) = value 46 shrl $23,r0,r2 # extract sign,exponent of value 47 andl2 $255,r2 # exponent 48 subl2 $152,r2 # e-152 49 /* 50 * If it overflowed then value>=2^31 and e>=160 51 * so we mask only r1 (low bits of fraction), not r0 52 */ 53 mnegl $1,r3 54 shrl r2,r3,r3 # -1>>(e-152) is neg mask to clear fraction 55 mcoml r3,r3 # complement mask 56 andl2 r3,r1 # mask off truly fractional bits from fraction 57 ldd r0 # now (r0,r1) = integerized value 58 std *12(fp) # *iptr = integerized 59 ldd 4(fp) 60 subd r0 61 std r0 # return fraction 62 ret 63