Deleted Added
full compact
s_roundl.c (153017) s_roundl.c (257770)
1/*-
2 * Copyright (c) 2003, Steven G. Kargl
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003, Steven G. Kargl
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/msun/src/s_roundl.c 153017 2005-12-02 13:45:06Z bde $");
28__FBSDID("$FreeBSD: head/lib/msun/src/s_roundl.c 257770 2013-11-06 23:44:52Z kargl $");
29
29
30#include <math.h>
30#include <float.h>
31#ifdef __i386__
32#include <ieeefp.h>
33#endif
31
34
35#include "fpmath.h"
36#include "math.h"
37#include "math_private.h"
38
32long double
33roundl(long double x)
34{
35 long double t;
39long double
40roundl(long double x)
41{
42 long double t;
43 uint16_t hx;
36
44
37 if (!isfinite(x))
38 return (x);
45 GET_LDBL_EXPSIGN(hx, x);
46 if ((hx & 0x7fff) == 0x7fff)
47 return (x + x);
39
48
40 if (x >= 0.0) {
49 ENTERI();
50
51 if (!(hx & 0x8000)) {
41 t = floorl(x);
52 t = floorl(x);
42 if (t - x <= -0.5)
43 t += 1.0;
44 return (t);
53 if (t - x <= -0.5L)
54 t += 1;
55 RETURNI(t);
45 } else {
46 t = floorl(-x);
56 } else {
57 t = floorl(-x);
47 if (t + x <= -0.5)
48 t += 1.0;
49 return (-t);
58 if (t + x <= -0.5L)
59 t += 1;
60 RETURNI(-t);
50 }
51}
61 }
62}