n_round.c revision 1.1
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.1Sis__RCSID("$NetBSD: n_round.c,v 1.1 2006/01/17 13:16:08 is 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.1Sisdouble 381.1Sisround(double x) 391.1Sis{ 401.1Sis double t; 411.1Sis 421.1Sis if (x >= 0.0) { 431.1Sis t = ceil(x); 441.1Sis if (t - x > 0.5) 451.1Sis t -= 1.0; 461.1Sis return (t); 471.1Sis } else { 481.1Sis t = ceil(-x); 491.1Sis if (t + x > 0.5) 501.1Sis t -= 1.0; 511.1Sis return (-t); 521.1Sis } 531.1Sis} 54