s_roundl.c revision 144772
1144772Sdas/*-
2144772Sdas * Copyright (c) 2003, Steven G. Kargl
3144772Sdas * All rights reserved.
4144772Sdas *
5144772Sdas * Redistribution and use in source and binary forms, with or without
6144772Sdas * modification, are permitted provided that the following conditions
7144772Sdas * are met:
8144772Sdas * 1. Redistributions of source code must retain the above copyright
9144772Sdas *    notice unmodified, this list of conditions, and the following
10144772Sdas *    disclaimer.
11144772Sdas * 2. Redistributions in binary form must reproduce the above copyright
12144772Sdas *    notice, this list of conditions and the following disclaimer in the
13144772Sdas *    documentation and/or other materials provided with the distribution.
14144772Sdas *
15144772Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16144772Sdas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17144772Sdas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18144772Sdas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19144772Sdas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20144772Sdas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21144772Sdas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22144772Sdas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23144772Sdas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24144772Sdas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25144772Sdas */
26144772Sdas
27144772Sdas#include <sys/cdefs.h>
28144772Sdas__FBSDID("$FreeBSD: head/lib/msun/src/s_roundl.c 144772 2005-04-08 01:24:08Z das $");
29144772Sdas
30144772Sdas#include <math.h>
31144772Sdas
32144772Sdaslong double
33144772Sdasroundl(long double x)
34144772Sdas{
35144772Sdas	long double t;
36144772Sdas
37144772Sdas	if (!isfinite(x))
38144772Sdas		return (x);
39144772Sdas
40144772Sdas	if (x >= 0.0) {
41144772Sdas		t = ceill(x);
42144772Sdas		if (t - x > 0.5)
43144772Sdas			t -= 1.0;
44144772Sdas		return (t);
45144772Sdas	} else {
46144772Sdas		t = ceill(-x);
47144772Sdas		if (t + x > 0.5)
48144772Sdas			t -= 1.0;
49144772Sdas		return (-t);
50144772Sdas	}
51144772Sdas}
52