Add noieee versions for lround(), lroundf(), lrint(), lrintf(),

llrint() and llrintf().  Code copied from round(), roundf() and
rint() and modified for return values.  Its possible this may not
do the right things in edge cases, but if so its likely to have
the same issues as the existing round(), roundf() and rint().

All this used by vax (only), and should allow xnest to complete
build.
This commit is contained in:
abs 2010-12-09 22:52:59 +00:00
parent 92c8678b42
commit eb439bf1a7
4 changed files with 181 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.98 2010/09/15 16:11:29 christos Exp $
# $NetBSD: Makefile,v 1.99 2010/12/09 22:52:59 abs Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@ -163,7 +163,7 @@ NOIEEE_SRCS = n_asincos.c n_acosh.c n_asinh.c n_atan.c n_atanh.c n_cosh.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_sincos.c n_tan.c \
n_round.c n_roundf.c
n_round.c n_roundf.c n_lround.c n_lroundf.c
# n_sqrt.c n_argred.c n_infnan.c n_atan2.c n_cabs.c n_cbrt.c n_support.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: n_floor.c,v 1.6 2004/05/13 20:35:40 mhitch Exp $ */
/* $NetBSD: n_floor.c,v 1.7 2010/12/09 22:52:59 abs Exp $ */
/*
* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
@ -144,3 +144,75 @@ rint(double x)
return (t - s);
}
#endif /* not national */
long
lrint(double x)
{
double s;
volatile double t;
const double one = 1.0;
#if !defined(__vax__)&&!defined(tahoe)
if (x != x) /* NaN */
return (x);
#endif /* !defined(__vax__)&&!defined(tahoe) */
if (copysign(x,one) >= L) /* already an integer */
return (x);
s = copysign(L,x);
t = x + s; /* x+s rounded to integer */
return (t - s);
}
long long
llrint(double x)
{
double s;
volatile double t;
const double one = 1.0;
#if !defined(__vax__)&&!defined(tahoe)
if (x != x) /* NaN */
return (x);
#endif /* !defined(__vax__)&&!defined(tahoe) */
if (copysign(x,one) >= L) /* already an integer */
return (x);
s = copysign(L,x);
t = x + s; /* x+s rounded to integer */
return (t - s);
}
long
lrintf(float x)
{
float s;
volatile float t;
const float one = 1.0;
#if !defined(__vax__)&&!defined(tahoe)
if (x != x) /* NaN */
return (x);
#endif /* !defined(__vax__)&&!defined(tahoe) */
if (copysign(x,one) >= L) /* already an integer */
return (x);
s = copysign(L,x);
t = x + s; /* x+s rounded to integer */
return (t - s);
}
long long
llrintf(float x)
{
float s;
volatile float t;
const float one = 1.0;
#if !defined(__vax__)&&!defined(tahoe)
if (x != x) /* NaN */
return (x);
#endif /* !defined(__vax__)&&!defined(tahoe) */
if (copysign(x,one) >= L) /* already an integer */
return (x);
s = copysign(L,x);
t = x + s; /* x+s rounded to integer */
return (t - s);
}

View File

@ -0,0 +1,53 @@
/*-
* 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 <sys/cdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: n_lround.c,v 1.1 2010/12/09 22:52:59 abs Exp $");
#if 0
__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp $");
#endif
#endif
#include <math.h>
long
lround(double x)
{
long t;
if (x >= 0.0) {
t = ceil(x);
if (t - x > 0.5)
t -= 1.0;
return (t);
} else {
t = ceil(-x);
if (t + x > 0.5)
t -= 1.0;
return (-t);
}
}

View File

@ -0,0 +1,53 @@
/*-
* 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 <sys/cdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: n_lroundf.c,v 1.1 2010/12/09 22:52:59 abs Exp $");
#if 0
__FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.1 2004/06/07 08:05:36 das Exp $");
#endif
#endif
#include <math.h>
long
lroundf(float x)
{
long t;
if (x >= 0.0) {
t = ceilf(x);
if (t - x > 0.5)
t -= 1.0;
return (t);
} else {
t = ceilf(-x);
if (t + x > 0.5)
t -= 1.0;
return (-t);
}
}