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$");
29130179Sdas
30130179Sdas#include <math.h>
31130179Sdas
32130179Sdasfloat
33130179Sdasroundf(float x)
34130179Sdas{
35130179Sdas	float t;
36130179Sdas
37140188Sdas	if (!isfinite(x))
38130179Sdas		return (x);
39130179Sdas
40130179Sdas	if (x >= 0.0) {
41153017Sbde		t = floorf(x);
42153017Sbde		if (t - x <= -0.5)
43153017Sbde			t += 1.0;
44130179Sdas		return (t);
45130179Sdas	} else {
46153017Sbde		t = floorf(-x);
47153017Sbde		if (t + x <= -0.5)
48153017Sbde			t += 1.0;
49130179Sdas		return (-t);
50130179Sdas	}
51130179Sdas}
52