summaryrefslogtreecommitdiff
path: root/lib/libm
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2008-06-11 14:35:34 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2008-06-11 14:35:34 +0000
commitcaff804d9651c0fdc6dc69eb95ee74f171f4d04f (patch)
tree92bca615eb5cd62b91e25dc736277cd9b07e35f2 /lib/libm
parent7d4c25336dc2169f39cb845f2baec04fcbcb7102 (diff)
add C99 round(), based on ieee_src, for noieee_src. tested on VAX
ok millert@
Diffstat (limited to 'lib/libm')
-rw-r--r--lib/libm/Makefile5
-rw-r--r--lib/libm/noieee_src/n_round.c47
2 files changed, 50 insertions, 2 deletions
diff --git a/lib/libm/Makefile b/lib/libm/Makefile
index 57cb541cb30..8c1bf3b57d5 100644
--- a/lib/libm/Makefile
+++ b/lib/libm/Makefile
@@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.28 1995/11/20 22:06:19 jtc Exp $
-# $OpenBSD: Makefile,v 1.41 2006/09/25 20:25:41 kettenis Exp $
+# $OpenBSD: Makefile,v 1.42 2008/06/11 14:35:33 martynas Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@@ -134,7 +134,8 @@ NOIEEE_SRCS = n_asincos.c n_acosh.c n_asinh.c n_atan.c n_atanh.c n_cosh.c \
n_erf.c n_exp.c n_exp__E.c n_expm1.c n_floor.c n_fmod.c n_gamma.c \
n_lgamma.c n_j0.c n_j1.c n_jn.c n_log.c n_log10.c n_log1p.c \
n_log__L.c n_pow.c n_sinh.c n_tanh.c n_atan2.c n_cabs.c n_cbrt.c \
- n_sqrt.c n_sincos.c n_tan.c n_argred.c n_support.c n_infnan.c
+ n_sqrt.c n_sincos.c n_tan.c n_argred.c n_support.c n_infnan.c \
+ n_round.c
# NetBSD's C library supplies these functions:
diff --git a/lib/libm/noieee_src/n_round.c b/lib/libm/noieee_src/n_round.c
new file mode 100644
index 00000000000..f45badca52e
--- /dev/null
+++ b/lib/libm/noieee_src/n_round.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: n_round.c,v 1.1 2008/06/11 14:35:33 martynas Exp $ */
+
+/*-
+ * Copyright (c) 2003, Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "math.h"
+
+double
+round(double x)
+{
+ double t;
+
+ if (x >= 0.0) {
+ t = floor(x);
+ if (t - x <= -0.5)
+ t += 1.0;
+ return (t);
+ } else {
+ t = floor(-x);
+ if (t + x <= -0.5)
+ t += 1.0;
+ return (-t);
+ }
+}