xref: /csrg-svn/lib/libc/mips/gen/modf.s (revision 52707)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
12	ASMSTR("@(#)modf.s	5.1 (Berkeley) 02/29/92")
13#endif /* LIBC_SCCS and not lint */
14
15#include "DEFS.h"
16
17/*
18 * double modf(val, iptr)
19 *	double val, *iptr;
20 * returns: xxx and n (in *iptr) where val == n.xxx
21 */
22LEAF(modf)
23	li.d	$f6, 4503599627370496.0	# check for value out of range (2**52)
24	abs.d	$f0, $f12
25	c.lt.d	$f0, $f6
26	mfc1	t0, $f13		# get the sign & exponent part
27	bc1f	3f			# val is not less than maxint
28	add.d	$f2, $f0, $f6		# logical shift right
29	sub.d	$f2, $f2, $f6		# logical shift left
30	c.le.d	$f2, $f0
31	bc1t	1f
32	li.d	$f6, 1.0		# adjust due to rounding
33	sub.d	$f2, $f2, $f6
341:
35	bge	t0, zero, 2f		# jump if val >= 0
36	neg.d	$f2, $f0		# negate integer part if val < 0
372:
38	s.d	$f2, 0(a2)		# save the integer part
39	sub.d	$f0, $f12, $f2		# return the fractional part
40	j	ra
413:
42	mtc1	zero, $f0		# val was too big so
43	mtc1	zero, $f1		#   return fraction of zero
44	s.d	$f12, 0(a2)		#   and the original number.
45	j	ra
46END(modf)
47