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