Cygwin: Add new APIs tc[gs]etwinsize()
[newlib-cygwin.git] / newlib / libm / machine / i386 / f_llrint.c
blob6cc81ea1f2dc1ec5c1fc0a01da8e40820a04cde1
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 */
10 #ifdef __GNUC__
11 #if !defined(_SOFT_FLOAT)
13 #include <math.h>
16 FUNCTION
17 <<llrint>>, <<llrintf>>, <<llrintl>>---round and convert to long long integer
18 INDEX
19 llrint
20 INDEX
21 llrintf
22 INDEX
23 llrintl
25 SYNOPSIS
26 #include <math.h>
27 long long int llrint(double x);
28 long long int llrintf(float x);
29 long long int llrintl(long double x);
31 DESCRIPTION
32 The <<llrint>>, <<llrintf>> and <<llrintl>> functions round <[x]> to the nearest integer value,
33 according to the current rounding direction. If the rounded value is outside the
34 range of the return type, the numeric result is unspecified. A range error may
35 occur if the magnitude of <[x]> is too large.
37 RETURNS
38 These functions return the rounded integer value of <[x]>.
39 <<llrint>>, <<llrintf>> and <<llrintl>> return the result as a long long integer.
41 PORTABILITY
42 <<llrint>>, <<llrintf>> and <<llrintl>> are ANSI.
43 The fast math versions of <<llrint>>, <<llrintf>> and <<llrintl>> are only
44 available on i386 platforms when hardware floating point support is available
45 and when compiling with GCC.
50 * Fast math version of llrint(x)
51 * Return x rounded to integral value according to the prevailing
52 * rounding mode.
53 * Method:
54 * Using inline x87 asms.
55 * Exception:
56 * Governed by x87 FPCR.
59 long long int _f_llrint (double x)
61 long long int _result;
62 asm ("fistpll %0" : "=m" (_result) : "t" (x) : "st");
63 return _result;
66 #endif /* !_SOFT_FLOAT */
67 #endif /* __GNUC__ */