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
23 /*
24 FUNCTION
25 <<rint>>, <<rintf>>, <<rintl>>---round to integer
26 INDEX
27 rint
28 INDEX
29 rintf
30 INDEX
31 rintl
32
33 SYNOPSIS
34 #include <math.h>
35 double rint(double x);
36 float rintf(float x);
37 long double rintl(long double x);
38
39 DESCRIPTION
40 The <<rint>>, <<rintf>> and <<rintl>> functions round <[x]> to an integer value
41 in floating-point format, using the current rounding direction. They may
42 raise the inexact exception if the result differs in value from the argument.
43
44 RETURNS
45 These functions return the rounded integer value of <[x]>.
46
47 PORTABILITY
48 <<rint>>, <<rintf>> and <<rintl>> are ANSI.
49 <<rint>> and <<rintf>> are available on all platforms.
50 <<rintl>> is only available on i386 platforms when hardware
51 floating point support is available and when compiling with GCC.
52
53 */
54
55 /*
56 * Fast math version of rint(x)
57 * Return x rounded to integral value according to the prevailing
58 * rounding mode.
59 * Method:
60 * Using inline x87 asms.
61 * Exception:
62 * Governed by x87 FPCR.
63 */
64
_f_rint(double x)65 double _f_rint (double x)
66 {
67 double _result;
68 __asm__("frndint" : "=t" (_result) : "0" (x));
69 return _result;
70 }
71
72 #endif /* !__GNUC__ || _SOFT_FLOAT */
73
74