Deleted Added
full compact
s_roundf.c (153017) s_roundf.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_roundf.c 153017 2005-12-02 13:45:06Z bde $");
28__FBSDID("$FreeBSD: head/lib/msun/src/s_roundf.c 257770 2013-11-06 23:44:52Z kargl $");
29
29
30#include <math.h>
30#include "math.h"
31#include "math_private.h"
31
32float
33roundf(float x)
34{
35 float t;
32
33float
34roundf(float x)
35{
36 float t;
37 uint32_t hx;
36
38
37 if (!isfinite(x))
38 return (x);
39 GET_FLOAT_WORD(hx, x);
40 if ((hx & 0x7fffffff) == 0x7f800000)
41 return (x + x);
39
42
40 if (x >= 0.0) {
43 if (!(hx & 0x80000000)) {
41 t = floorf(x);
44 t = floorf(x);
42 if (t - x <= -0.5)
43 t += 1.0;
45 if (t - x <= -0.5F)
46 t += 1;
44 return (t);
45 } else {
46 t = floorf(-x);
47 return (t);
48 } else {
49 t = floorf(-x);
47 if (t + x <= -0.5)
48 t += 1.0;
50 if (t + x <= -0.5F)
51 t += 1;
49 return (-t);
50 }
51}
52 return (-t);
53 }
54}