s_round.c (153017) | s_round.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_round.c 153017 2005-12-02 13:45:06Z bde $"); | 28__FBSDID("$FreeBSD: head/lib/msun/src/s_round.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 32double 33round(double x) 34{ 35 double t; | 32 33double 34round(double x) 35{ 36 double t; |
37 uint32_t hx; |
|
36 | 38 |
37 if (!isfinite(x)) 38 return (x); | 39 GET_HIGH_WORD(hx, x); 40 if ((hx & 0x7fffffff) == 0x7ff00000) 41 return (x + x); |
39 | 42 |
40 if (x >= 0.0) { | 43 if (!(hx & 0x80000000)) { |
41 t = floor(x); 42 if (t - x <= -0.5) | 44 t = floor(x); 45 if (t - x <= -0.5) |
43 t += 1.0; | 46 t += 1; |
44 return (t); 45 } else { 46 t = floor(-x); 47 if (t + x <= -0.5) | 47 return (t); 48 } else { 49 t = floor(-x); 50 if (t + x <= -0.5) |
48 t += 1.0; | 51 t += 1; |
49 return (-t); 50 } 51} | 52 return (-t); 53 } 54} |