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