11.1Sis/*-
21.1Sis * Copyright (c) 2003, Steven G. Kargl
31.1Sis * All rights reserved.
41.1Sis *
51.1Sis * Redistribution and use in source and binary forms, with or without
61.1Sis * modification, are permitted provided that the following conditions
71.1Sis * are met:
81.1Sis * 1. Redistributions of source code must retain the above copyright
91.1Sis *    notice unmodified, this list of conditions, and the following
101.1Sis *    disclaimer.
111.1Sis * 2. Redistributions in binary form must reproduce the above copyright
121.1Sis *    notice, this list of conditions and the following disclaimer in the
131.1Sis *    documentation and/or other materials provided with the distribution.
141.1Sis *
151.1Sis * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.1Sis * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171.1Sis * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181.1Sis * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191.1Sis * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201.1Sis * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211.1Sis * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221.1Sis * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231.1Sis * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241.1Sis * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251.1Sis */
261.1Sis
271.1Sis#include <sys/cdefs.h>
281.1Sis#if defined(LIBM_SCCS) && !defined(lint)
291.2Smartin__RCSID("$NetBSD: n_round.c,v 1.2 2014/03/16 10:02:27 martin Exp $");
301.1Sis#if 0
311.1Sis__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp $");
321.1Sis#endif
331.1Sis#endif
341.1Sis
351.1Sis#include <math.h>
361.1Sis
371.2Smartin#ifdef __weak_alias
381.2Smartin__weak_alias(roundl, round);
391.2Smartin#endif
401.2Smartin
411.1Sisdouble
421.1Sisround(double x)
431.1Sis{
441.1Sis	double t;
451.1Sis
461.1Sis	if (x >= 0.0) {
471.1Sis		t = ceil(x);
481.1Sis		if (t - x > 0.5)
491.1Sis			t -= 1.0;
501.1Sis		return (t);
511.1Sis	} else {
521.1Sis		t = ceil(-x);
531.1Sis		if (t + x > 0.5)
541.1Sis			t -= 1.0;
551.1Sis		return (-t);
561.1Sis	}
571.1Sis}
58