1 /*
2 Copyright (c) 2007 Dave Korn
3 
4 
5 x87 FP implementation contributed to Newlib by
6 Dave Korn, November 2007.  This file is placed in the
7 public domain.  Permission to use, copy, modify, and
8 distribute this software is freely granted.
9  */
10 /*
11  * ====================================================
12  * x87 FP implementation contributed to Newlib by
13  * Dave Korn, November 2007.  This file is placed in the
14  * public domain.  Permission to use, copy, modify, and
15  * distribute this software is freely granted.
16  * ====================================================
17  */
18 
19 #if defined(__GNUC__) && !defined(_SOFT_FLOAT)
20 
21 #include <math.h>
22 #include "f_math.h"
23 
24 /*
25 FUNCTION
26 <<rint>>, <<rintf>>, <<rintl>>---round to integer
27 INDEX
28 	rint
29 INDEX
30 	rintf
31 INDEX
32 	rintl
33 
34 SYNOPSIS
35 	#include <math.h>
36 	double rint(double x);
37         float rintf(float x);
38         long double rintl(long double x);
39 
40 DESCRIPTION
41 The <<rint>>, <<rintf>> and <<rintl>> functions round <[x]> to an integer value
42 in floating-point format, using the current rounding direction.  They may
43 raise the inexact exception if the result differs in value from the argument.
44 
45 RETURNS
46 These functions return the rounded integer value of <[x]>.
47 
48 PORTABILITY
49 <<rint>>, <<rintf>> and <<rintl>> are ANSI.
50 <<rint>> and <<rintf>> are available on all platforms.
51 <<rintl>> is only available on i386 platforms when hardware
52 floating point support is available and when compiling with GCC.
53 
54 */
55 
56 /*
57  * Fast math version of rint(x)
58  * Return x rounded to integral value according to the prevailing
59  * rounding mode.
60  * Method:
61  *	Using inline x87 asms.
62  * Exception:
63  *	Governed by x87 FPCR.
64  */
65 
_f_rint(double x)66 double _f_rint (double x)
67 {
68   double _result;
69   __asm__("frndint" : "=t" (_result) : "0" (x));
70   return _result;
71 }
72 
73 #endif  /* !__GNUC__ || _SOFT_FLOAT */
74 
75