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