1 /* Round to int long double floating-point values.
2 IBM extended format long double version.
3 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 /* This has been coded in assembler because GCC makes such a mess of it
22 when it's coded in C. */
25 #include <math_ldbl_opt.h>
32 __rintl (long double x
)
39 static const long double TWO52
= 4503599627370496.0L;
40 union ibm_extended_long_double u
;
43 if (fabs (u
.dd
[0]) < TWO52
)
45 double high
= u
.dd
[0];
50 if (high
== -0.0) high
= 0.0;
56 if (high
== 0.0) high
= -0.0;
61 else if (fabs (u
.dd
[1]) < TWO52
&& u
.dd
[1] != 0.0)
63 double high
, low
, tau
;
64 /* In this case we have to round the low double and handle any
65 adjustment to the high double that may be caused by rounding
66 (up). This is complicated by the fact that the high double
67 may already be rounded and the low double may have the
68 opposite sign to compensate. */
73 /* If the high/low doubles are the same sign then simply
74 round the low double. */
78 else if (u
.dd
[1] < 0.0)
80 /* Else the high double is pre rounded and we need to
83 tau
= nextafter (u
.dd
[0], 0.0);
84 tau
= (u
.dd
[0] - tau
) * 2.0;
91 else if (u
.dd
[0] < 0.0)
95 /* If the high/low doubles are the same sign then simply
96 round the low double. */
100 else if (u
.dd
[1] > 0.0)
102 /* Else the high double is pre rounded and we need to
104 tau
= nextafter (u
.dd
[0], 0.0);
105 tau
= (u
.dd
[0] - tau
) * 2.0;
106 high
= u
.dd
[0] - tau
;
110 low
= -(low
- TWO52
);
112 u
.dd
[0] = high
+ low
;
113 u
.dd
[1] = high
- u
.dd
[0] + low
;
119 long_double_symbol (libm
, __rintl
, rintl
);