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