xref: /csrg-svn/lib/libc/mips/gen/modf.s (revision 52739)
152707Sbostic/*-
252707Sbostic * Copyright (c) 1991 The Regents of the University of California.
352707Sbostic * All rights reserved.
452707Sbostic *
552707Sbostic * This code is derived from software contributed to Berkeley by
652707Sbostic * Ralph Campbell.
752707Sbostic *
852707Sbostic * %sccs.include.redist.c%
952707Sbostic */
1052707Sbostic
11*52739Sbostic#include "DEFS.h"
12*52739Sbostic
1352707Sbostic#if defined(LIBC_SCCS) && !defined(lint)
14*52739Sbostic	ASMSTR("@(#)modf.s	5.2 (Berkeley) 02/29/92")
1552707Sbostic#endif /* LIBC_SCCS and not lint */
1652707Sbostic
1752707Sbostic/*
1852707Sbostic * double modf(val, iptr)
1952707Sbostic *	double val, *iptr;
2052707Sbostic * returns: xxx and n (in *iptr) where val == n.xxx
2152707Sbostic */
2252707SbosticLEAF(modf)
2352707Sbostic	li.d	$f6, 4503599627370496.0	# check for value out of range (2**52)
2452707Sbostic	abs.d	$f0, $f12
2552707Sbostic	c.lt.d	$f0, $f6
2652707Sbostic	mfc1	t0, $f13		# get the sign & exponent part
2752707Sbostic	bc1f	3f			# val is not less than maxint
2852707Sbostic	add.d	$f2, $f0, $f6		# logical shift right
2952707Sbostic	sub.d	$f2, $f2, $f6		# logical shift left
3052707Sbostic	c.le.d	$f2, $f0
3152707Sbostic	bc1t	1f
3252707Sbostic	li.d	$f6, 1.0		# adjust due to rounding
3352707Sbostic	sub.d	$f2, $f2, $f6
3452707Sbostic1:
3552707Sbostic	bge	t0, zero, 2f		# jump if val >= 0
3652707Sbostic	neg.d	$f2, $f0		# negate integer part if val < 0
3752707Sbostic2:
3852707Sbostic	s.d	$f2, 0(a2)		# save the integer part
3952707Sbostic	sub.d	$f0, $f12, $f2		# return the fractional part
4052707Sbostic	j	ra
4152707Sbostic3:
4252707Sbostic	mtc1	zero, $f0		# val was too big so
4352707Sbostic	mtc1	zero, $f1		#   return fraction of zero
4452707Sbostic	s.d	$f12, 0(a2)		#   and the original number.
4552707Sbostic	j	ra
4652707SbosticEND(modf)
47