1130179Sdas/*-
2130179Sdas * Copyright (c) 2003, Steven G. Kargl
3130179Sdas * All rights reserved.
4130179Sdas *
5130179Sdas * Redistribution and use in source and binary forms, with or without
6130179Sdas * modification, are permitted provided that the following conditions
7130179Sdas * are met:
8130179Sdas * 1. Redistributions of source code must retain the above copyright
9130179Sdas *    notice unmodified, this list of conditions, and the following
10130179Sdas *    disclaimer.
11130179Sdas * 2. Redistributions in binary form must reproduce the above copyright
12130179Sdas *    notice, this list of conditions and the following disclaimer in the
13130179Sdas *    documentation and/or other materials provided with the distribution.
14130179Sdas *
15130179Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16130179Sdas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17130179Sdas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18130179Sdas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19130179Sdas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20130179Sdas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21130179Sdas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22130179Sdas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23130179Sdas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24130179Sdas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25130179Sdas */
26130179Sdas
27130179Sdas#include <sys/cdefs.h>
28130179Sdas__FBSDID("$FreeBSD: releng/10.2/lib/msun/src/s_round.c 271779 2014-09-18 15:10:22Z tijl $");
29130179Sdas
30271779Stijl#include <float.h>
31130179Sdas
32271779Stijl#include "math.h"
33271779Stijl#include "math_private.h"
34271779Stijl
35130179Sdasdouble
36130179Sdasround(double x)
37130179Sdas{
38130179Sdas	double t;
39271779Stijl	uint32_t hx;
40130179Sdas
41271779Stijl	GET_HIGH_WORD(hx, x);
42271779Stijl	if ((hx & 0x7fffffff) == 0x7ff00000)
43271779Stijl		return (x + x);
44130179Sdas
45271779Stijl	if (!(hx & 0x80000000)) {
46153017Sbde		t = floor(x);
47153017Sbde		if (t - x <= -0.5)
48271779Stijl			t += 1;
49130179Sdas		return (t);
50130179Sdas	} else {
51153017Sbde		t = floor(-x);
52153017Sbde		if (t + x <= -0.5)
53271779Stijl			t += 1;
54130179Sdas		return (-t);
55130179Sdas	}
56130179Sdas}
57271779Stijl
58271779Stijl#if (LDBL_MANT_DIG == 53)
59271779Stijl__weak_reference(round, roundl);
60271779Stijl#endif
61