s_roundf.c revision 133146
119370Spst/*- 219370Spst * Copyright (c) 2003, Steven G. Kargl 319370Spst * All rights reserved. 419370Spst * 519370Spst * Redistribution and use in source and binary forms, with or without 619370Spst * modification, are permitted provided that the following conditions 719370Spst * are met: 819370Spst * 1. Redistributions of source code must retain the above copyright 919370Spst * notice unmodified, this list of conditions, and the following 1019370Spst * disclaimer. 1119370Spst * 2. Redistributions in binary form must reproduce the above copyright 1219370Spst * notice, this list of conditions and the following disclaimer in the 1319370Spst * documentation and/or other materials provided with the distribution. 1419370Spst * 1519370Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1619370Spst * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1719370Spst * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1819370Spst * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1919370Spst * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2019370Spst * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2119370Spst * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2219370Spst * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2319370Spst * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2419370Spst * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2519370Spst */ 2619370Spst 2719370Spst#include <sys/cdefs.h> 2819370Spst__FBSDID("$FreeBSD: head/lib/msun/src/s_roundf.c 133146 2004-08-05 01:44:55Z das $"); 2919370Spst 3019370Spst#include <math.h> 3119370Spst 3219370Spstfloat 3319370Spstroundf(float x) 3419370Spst{ 3519370Spst float t; 3619370Spst 3719370Spst if (!isnormal(x)) 3819370Spst return (x); 3919370Spst 4019370Spst if (x >= 0.0) { 4119370Spst t = ceilf(x); 4219370Spst if (t - x > 0.5) 4319370Spst t -= 1.0; 4419370Spst return (t); 4519370Spst } else { 4619370Spst t = ceilf(-x); 4719370Spst if (t + x > 0.5) 4819370Spst t -= 1.0; 4919370Spst return (-t); 5019370Spst } 5119370Spst} 5219370Spst