n_lroundf.c revision 1.1 1 1.1 abs /*-
2 1.1 abs * Copyright (c) 2003, Steven G. Kargl
3 1.1 abs * All rights reserved.
4 1.1 abs *
5 1.1 abs * Redistribution and use in source and binary forms, with or without
6 1.1 abs * modification, are permitted provided that the following conditions
7 1.1 abs * are met:
8 1.1 abs * 1. Redistributions of source code must retain the above copyright
9 1.1 abs * notice unmodified, this list of conditions, and the following
10 1.1 abs * disclaimer.
11 1.1 abs * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 abs * notice, this list of conditions and the following disclaimer in the
13 1.1 abs * documentation and/or other materials provided with the distribution.
14 1.1 abs *
15 1.1 abs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 abs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 abs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 abs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 abs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 abs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 abs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 abs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 abs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 abs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 abs */
26 1.1 abs
27 1.1 abs #include <sys/cdefs.h>
28 1.1 abs #if defined(LIBM_SCCS) && !defined(lint)
29 1.1 abs __RCSID("$NetBSD: n_lroundf.c,v 1.1 2010/12/09 22:52:59 abs Exp $");
30 1.1 abs #if 0
31 1.1 abs __FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.1 2004/06/07 08:05:36 das Exp $");
32 1.1 abs #endif
33 1.1 abs #endif
34 1.1 abs
35 1.1 abs #include <math.h>
36 1.1 abs
37 1.1 abs long
38 1.1 abs lroundf(float x)
39 1.1 abs {
40 1.1 abs long t;
41 1.1 abs
42 1.1 abs if (x >= 0.0) {
43 1.1 abs t = ceilf(x);
44 1.1 abs if (t - x > 0.5)
45 1.1 abs t -= 1.0;
46 1.1 abs return (t);
47 1.1 abs } else {
48 1.1 abs t = ceilf(-x);
49 1.1 abs if (t + x > 0.5)
50 1.1 abs t -= 1.0;
51 1.1 abs return (-t);
52 1.1 abs }
53 1.1 abs }
54