|
|
1.1 root 1: /*
2: * Copyright (c) 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: *
17: * This code is derived from software contributed to Berkeley by
18: * Computer Consoles Inc.
19: */
20:
21: #if defined(LIBC_SCCS) && !defined(lint)
22: .asciz "@(#)modf.s 1.4 (Berkeley) 6/27/88"
23: #endif /* LIBC_SCCS and not lint */
24:
25: /*
26: * double modf (value, iptr)
27: * double value, *iptr;
28: *
29: * Modf returns the fractional part of "value",
30: * and stores the integer part indirectly through "iptr".
31: *
32: * This version uses floating point (look in ../fpe for
33: * a much slower integer version).
34: */
35:
36: #include "DEFS.h"
37:
38: ENTRY(modf, 0)
39: ldd 4(fp) # value
40: cvdl r2 # integerize
41: bvs 1f # did integer part overflow?
42: cvld r2 # integer part
43: std r0
44: std *12(fp) # *iptr = r2
45: ldd 4(fp)
46: subd r0 # value-(int)value
47: std r0 # return fraction
48: ret
49: 1:
50: /*
51: * If the integer portion overflowed, mask out the fractional
52: * bits in the double word instead of cvdl-ing.
53: */
54: ldd 4(fp)
55: std r0 # (r0,r1) = value
56: shrl $23,r0,r2 # extract sign,exponent of value
57: andl2 $255,r2 # exponent
58: subl2 $152,r2 # e-152
59: /*
60: * If it overflowed then value>=2^31 and e>=160
61: * so we mask only r1 (low bits of fraction), not r0
62: */
63: mnegl $1,r3
64: shrl r2,r3,r3 # -1>>(e-152) is neg mask to clear fraction
65: mcoml r3,r3 # complement mask
66: andl2 r3,r1 # mask off truly fractional bits from fraction
67: ldd r0 # now (r0,r1) = integerized value
68: std *12(fp) # *iptr = integerized
69: ldd 4(fp)
70: subd r0
71: std r0 # return fraction
72: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.