Add initial version of ceill, floorl and roundl from FreeBSD.
This commit is contained in:
parent
b17548bd54
commit
2e412cf6b8
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.143 2013/10/15 23:59:36 joerg Exp $
|
||||
# $NetBSD: Makefile,v 1.144 2013/11/11 23:57:34 joerg Exp $
|
||||
#
|
||||
# @(#)Makefile 5.1beta 93/09/24
|
||||
#
|
||||
@ -158,15 +158,18 @@ COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c \
|
||||
e_scalbf.c e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \
|
||||
k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c \
|
||||
k_standard.c k_tan.c k_tanf.c \
|
||||
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c s_ceil.c \
|
||||
s_ceilf.c s_copysign.c s_copysignf.c s_copysignl.c s_cos.c s_cosf.c s_erf.c \
|
||||
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c \
|
||||
s_ceil.c s_ceilf.c s_ceill.c s_copysign.c s_copysignf.c s_copysignl.c \
|
||||
s_cos.c s_cosf.c s_erf.c \
|
||||
s_erff.c s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fabsl.c \
|
||||
s_finite.c s_finitef.c \
|
||||
s_floor.c s_floorf.c s_frexpf.c s_ilogb.c s_ilogbf.c s_ilogbl.c \
|
||||
s_floor.c s_floorf.c s_floorl.c s_frexpf.c \
|
||||
s_ilogb.c s_ilogbf.c s_ilogbl.c \
|
||||
s_isinff.c s_isnanf.c s_lib_version.c s_log1p.c \
|
||||
s_log1pf.c s_logb.c s_logbf.c s_logbl.c \
|
||||
s_matherr.c s_modff.c s_nextafter.c s_nextafterl.c \
|
||||
s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c s_round.c s_roundf.c s_scalbn.c \
|
||||
s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \
|
||||
s_round.c s_roundf.c s_roundl.c s_scalbn.c \
|
||||
s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c s_sin.c \
|
||||
s_sinf.c s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \
|
||||
w_acos.c w_acosf.c w_acosh.c w_acoshf.c w_asin.c w_asinf.c w_atan2.c \
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: namespace.h,v 1.5 2013/01/28 06:26:20 matt Exp $ */
|
||||
/* $NetBSD: namespace.h,v 1.6 2013/11/11 23:57:34 joerg Exp $ */
|
||||
|
||||
#define atan2 _atan2
|
||||
#define atan2f _atan2f
|
||||
@ -45,3 +45,7 @@
|
||||
#define scalbln _scalbln
|
||||
#define scalblnf _scalblnf
|
||||
#define scalblnl _scalblnl
|
||||
|
||||
#define ceill _ceill
|
||||
#define floorl _floorl
|
||||
#define roundl _roundl
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_ceil.c,v 1.13 2009/02/16 01:22:18 lukem Exp $");
|
||||
__RCSID("$NetBSD: s_ceil.c,v 1.14 2013/11/11 23:57:34 joerg Exp $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -29,6 +29,11 @@ __RCSID("$NetBSD: s_ceil.c,v 1.13 2009/02/16 01:22:18 lukem Exp $");
|
||||
|
||||
static const double huge = 1.0e300;
|
||||
|
||||
#ifndef __HAVE_LONG_DOUBLE
|
||||
__strong_alias(_ceill, ceil)
|
||||
__weak_alias(ceill, ceil)
|
||||
#endif
|
||||
|
||||
double
|
||||
ceil(double x)
|
||||
{
|
||||
|
112
lib/libm/src/s_ceill.c
Normal file
112
lib/libm/src/s_ceill.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*
|
||||
* From: @(#)s_ceil.c 5.1 93/09/24
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: s_ceill.c,v 1.1 2013/11/11 23:57:34 joerg Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: head/lib/msun/src/s_ceill.c 176280 2008-02-14 15:10:34Z bde $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ceill(x)
|
||||
* Return x rounded toward -inf to integral value
|
||||
* Method:
|
||||
* Bit twiddling.
|
||||
* Exception:
|
||||
* Inexact flag raised if x not equal to ceill(x).
|
||||
*/
|
||||
#include "namespace.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <machine/ieee.h>
|
||||
|
||||
#ifdef __HAVE_LONG_DOUBLE
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(ceill, _ceill)
|
||||
#endif
|
||||
|
||||
#ifdef LDBL_IMPLICIT_NBIT
|
||||
#define MANH_SIZE (EXT_FRACHBITS + 1)
|
||||
#define INC_MANH(ux, c) do { \
|
||||
uint64_t oi = ux.extu_frach; \
|
||||
ux.extu_frach += (c); \
|
||||
if (ux.extu_frach < oi) \
|
||||
ux.extu_exp++; \
|
||||
} while (0)
|
||||
#else
|
||||
#define MANH_SIZE EXT_FRACHBITS
|
||||
#define INC_MANH(ux, c) do { \
|
||||
uint64_t oi = ux.extu_frach; \
|
||||
ux.extu_frach += (c); \
|
||||
if (ux.extu_frach < oi) { \
|
||||
ux.extu_exp++; \
|
||||
ux.extu_frach |= 1llu << (EXT_FRACHBITS - 1); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
static const long double huge = 1.0e300;
|
||||
|
||||
long double
|
||||
ceill(long double x)
|
||||
{
|
||||
union ieee_ext_u ux = { .extu_ld = x, };
|
||||
int e = ux.extu_exp - LDBL_MAX_EXP + 1;
|
||||
|
||||
if (e < MANH_SIZE - 1) {
|
||||
if (e < 0) { /* raise inexact if x != 0 */
|
||||
if (huge + x > 0.0)
|
||||
if (ux.extu_exp > 0 ||
|
||||
(ux.extu_frach | ux.extu_fracl) != 0)
|
||||
ux.extu_ld = ux.extu_sign ? -0.0 : 1.0;
|
||||
} else {
|
||||
uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
|
||||
if (((ux.extu_frach & m) | ux.extu_fracl) == 0)
|
||||
return (x); /* x is integral */
|
||||
if (!ux.extu_sign) {
|
||||
#ifdef LDBL_IMPLICIT_NBIT
|
||||
if (e == 0)
|
||||
ux.extu_exp++;
|
||||
else
|
||||
#endif
|
||||
INC_MANH(ux, 1llu << (MANH_SIZE - e - 1));
|
||||
}
|
||||
if (huge + x > 0.0) { /* raise inexact flag */
|
||||
ux.extu_frach &= ~m;
|
||||
ux.extu_fracl = 0;
|
||||
}
|
||||
}
|
||||
} else if (e < LDBL_MANT_DIG - 1) {
|
||||
uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
|
||||
if ((ux.extu_fracl & m) == 0)
|
||||
return (x); /* x is integral */
|
||||
if (!ux.extu_sign) {
|
||||
if (e == MANH_SIZE - 1)
|
||||
INC_MANH(ux, 1);
|
||||
else {
|
||||
uint64_t o = ux.extu_fracl;
|
||||
ux.extu_fracl += 1llu << (LDBL_MANT_DIG - e - 1);
|
||||
if (ux.extu_fracl < o) /* got a carry */
|
||||
INC_MANH(ux, 1);
|
||||
}
|
||||
}
|
||||
if (huge + x > 0.0) /* raise inexact flag */
|
||||
ux.extu_fracl &= ~m;
|
||||
}
|
||||
return (ux.extu_ld);
|
||||
}
|
||||
|
||||
#endif /* __HAVE_LONG_DOUBLE */
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_floor.c,v 1.13 2009/02/16 01:27:36 lukem Exp $");
|
||||
__RCSID("$NetBSD: s_floor.c,v 1.14 2013/11/11 23:57:34 joerg Exp $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -27,6 +27,11 @@ __RCSID("$NetBSD: s_floor.c,v 1.13 2009/02/16 01:27:36 lukem Exp $");
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
#ifndef __HAVE_LONG_DOUBLE
|
||||
__strong_alias(_floorl, floor)
|
||||
__weak_alias(floorl, floor)
|
||||
#endif
|
||||
|
||||
static const double huge = 1.0e300;
|
||||
|
||||
double
|
||||
|
112
lib/libm/src/s_floorl.c
Normal file
112
lib/libm/src/s_floorl.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*
|
||||
* From: @(#)s_floor.c 5.1 93/09/24
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: s_floorl.c,v 1.1 2013/11/11 23:57:34 joerg Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: head/lib/msun/src/s_floorl.c 176280 2008-02-14 15:10:34Z bde $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
* floorl(x)
|
||||
* Return x rounded toward -inf to integral value
|
||||
* Method:
|
||||
* Bit twiddling.
|
||||
* Exception:
|
||||
* Inexact flag raised if x not equal to floorl(x).
|
||||
*/
|
||||
#include "namespace.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <machine/ieee.h>
|
||||
|
||||
#ifdef __HAVE_LONG_DOUBLE
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(floorl, _floorl)
|
||||
#endif
|
||||
|
||||
#ifdef LDBL_IMPLICIT_NBIT
|
||||
#define MANH_SIZE (EXT_FRACHBITS + 1)
|
||||
#define INC_MANH(ux, c) do { \
|
||||
uint64_t oi = ux.extu_frach; \
|
||||
ux.extu_frach += (c); \
|
||||
if (ux.extu_frach < oi) \
|
||||
ux.extu_exp++; \
|
||||
} while (0)
|
||||
#else
|
||||
#define MANH_SIZE EXT_FRACHBITS
|
||||
#define INC_MANH(ux, c) do { \
|
||||
uint64_t oi = ux.extu_frach; \
|
||||
ux.extu_frach += (c); \
|
||||
if (ux.extu_frach < oi) { \
|
||||
ux.extu_exp++; \
|
||||
ux.extu_frach |= 1llu << (EXT_FRACHBITS - 1); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
static const long double huge = 1.0e300;
|
||||
|
||||
long double
|
||||
floorl(long double x)
|
||||
{
|
||||
union ieee_ext_u ux = { .extu_ld = x, };
|
||||
int e = ux.extu_exp - LDBL_MAX_EXP + 1;
|
||||
|
||||
if (e < MANH_SIZE - 1) {
|
||||
if (e < 0) { /* raise inexact if x != 0 */
|
||||
if (huge + x > 0.0)
|
||||
if (ux.extu_exp > 0 ||
|
||||
(ux.extu_frach | ux.extu_fracl) != 0)
|
||||
ux.extu_ld = ux.extu_sign ? -1.0 : 0.0;
|
||||
} else {
|
||||
uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
|
||||
if (((ux.extu_frach & m) | ux.extu_fracl) == 0)
|
||||
return (x); /* x is integral */
|
||||
if (ux.extu_sign) {
|
||||
#ifdef LDBL_IMPLICIT_NBIT
|
||||
if (e == 0)
|
||||
ux.extu_exp++;
|
||||
else
|
||||
#endif
|
||||
INC_MANH(ux, 1llu << (MANH_SIZE - e - 1));
|
||||
}
|
||||
if (huge + x > 0.0) { /* raise inexact flag */
|
||||
ux.extu_frach &= ~m;
|
||||
ux.extu_fracl = 0;
|
||||
}
|
||||
}
|
||||
} else if (e < LDBL_MANT_DIG - 1) {
|
||||
uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
|
||||
if ((ux.extu_fracl & m) == 0)
|
||||
return (x); /* x is integral */
|
||||
if (ux.extu_sign) {
|
||||
if (e == MANH_SIZE - 1)
|
||||
INC_MANH(ux, 1);
|
||||
else {
|
||||
uint64_t o = ux.extu_fracl;
|
||||
ux.extu_fracl += 1llu << (LDBL_MANT_DIG - e - 1);
|
||||
if (ux.extu_fracl < o) /* got a carry */
|
||||
INC_MANH(ux, 1);
|
||||
}
|
||||
}
|
||||
if (huge + x > 0.0) /* raise inexact flag */
|
||||
ux.extu_fracl &= ~m;
|
||||
}
|
||||
return (ux.extu_ld);
|
||||
}
|
||||
|
||||
#endif /* __HAVE_LONG_DOUBLE */
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_round.c,v 1.2 2007/08/21 20:10:27 drochner Exp $");
|
||||
__RCSID("$NetBSD: s_round.c,v 1.3 2013/11/11 23:57:34 joerg Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp $");
|
||||
#endif
|
||||
@ -34,6 +34,11 @@ __FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifndef __HAVE_LONG_DOUBLE
|
||||
__strong_alias(_roundl, round)
|
||||
__weak_alias(roundl, round)
|
||||
#endif
|
||||
|
||||
double
|
||||
round(double x)
|
||||
{
|
||||
|
63
lib/libm/src/s_roundl.c
Normal file
63
lib/libm/src/s_roundl.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*-
|
||||
* 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>
|
||||
__RCSID("$NetBSD: s_roundl.c,v 1.1 2013/11/11 23:57:34 joerg Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: head/lib/msun/src/s_roundl.c 153017 2005-12-02 13:45:06Z bde $");
|
||||
#endif
|
||||
|
||||
#include "namespace.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __HAVE_LONG_DOUBLE
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(roundl, _roundl)
|
||||
#endif
|
||||
|
||||
long double
|
||||
roundl(long double x)
|
||||
{
|
||||
long double t;
|
||||
|
||||
if (!isfinite(x))
|
||||
return (x);
|
||||
|
||||
if (x >= 0.0) {
|
||||
t = floorl(x);
|
||||
if (t - x <= -0.5)
|
||||
t += 1.0;
|
||||
return (t);
|
||||
} else {
|
||||
t = floorl(-x);
|
||||
if (t + x <= -0.5)
|
||||
t += 1.0;
|
||||
return (-t);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __HAVE_LONG_DOUBLE */
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_truncl.c,v 1.2 2012/08/08 16:58:28 matt Exp $");
|
||||
__RCSID("$NetBSD: s_truncl.c,v 1.3 2013/11/11 23:57:34 joerg Exp $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -43,6 +43,7 @@ __RCSID("$NetBSD: s_truncl.c,v 1.2 2012/08/08 16:58:28 matt Exp $");
|
||||
|
||||
#include <machine/ieee.h>
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
@ -53,17 +54,17 @@ static const long double huge = LDBL_MAX;
|
||||
long double
|
||||
truncl(long double x)
|
||||
{
|
||||
struct ieee_ext_u ux = { .extu_ld = x, };
|
||||
union ieee_ext_u ux = { .extu_ld = x, };
|
||||
int32_t exponent = ux.extu_exp - EXT_EXP_BIAS;
|
||||
#ifdef LDBL_MANT_DIG == EXT_FRACBITS
|
||||
#if LDBL_MANT_DIG == EXT_FRACBITS
|
||||
/*
|
||||
* If there is no hidden bit, don't count it
|
||||
*/
|
||||
const u_int frach_bits = EXT_FRACHBITS - 1;
|
||||
const u_int frac_bits = EXT_FRACBITS - 1;
|
||||
const int32_t frach_bits = EXT_FRACHBITS - 1;
|
||||
const int32_t frac_bits = EXT_FRACBITS - 1;
|
||||
#else
|
||||
const u_int frach_bits = EXT_FRACHBITS;
|
||||
const u_int frac_bits = EXT_FRACBITS;
|
||||
const int32_t frach_bits = EXT_FRACHBITS;
|
||||
const int32_t frac_bits = EXT_FRACBITS;
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -79,7 +80,7 @@ truncl(long double x)
|
||||
/*
|
||||
* If this number is too small enough to have any integral digits...
|
||||
*/
|
||||
if (exponent < 0 && (huge - x > 0.0 || true)) {
|
||||
if (exponent < 0 && huge - x > 0.0) {
|
||||
/* set inexact if x != 0 */
|
||||
/* |x|<1, so return 0*sign(x) */
|
||||
return ux.extu_sign ? -0.0 : 0.0;
|
||||
@ -89,6 +90,9 @@ truncl(long double x)
|
||||
#ifdef EXT_FRACHMBITS
|
||||
uint32_t frachm_mask = __BIT(EXT_FRACHMBITS) - 1;
|
||||
#endif
|
||||
#ifdef EXT_FRACLMBITS
|
||||
uint32_t fraclm_mask = __BIT(EXT_FRACLMBITS) - 1;
|
||||
#endif
|
||||
#ifdef EXT_FRACHMBITS
|
||||
uint32_t frachl_mask = __BIT(EXT_FRACLMBITS) - 1;
|
||||
#endif
|
||||
@ -128,7 +132,7 @@ truncl(long double x)
|
||||
&& (ux.extu_fracl & fracl_mask) == 0)
|
||||
return x; /* x is integral */
|
||||
|
||||
if (huge - x > 0.0 || true) { /* set inexact flag */
|
||||
if (huge - x > 0.0) { /* set inexact flag */
|
||||
/*
|
||||
* Clear any fractional bits...
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_ceil.c,v 1.7 2011/09/17 12:12:19 jruoho Exp $ */
|
||||
/* $NetBSD: t_ceil.c,v 1.8 2013/11/11 23:57:34 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
@ -29,7 +29,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_ceil.c,v 1.7 2011/09/17 12:12:19 jruoho Exp $");
|
||||
__RCSID("$NetBSD: t_ceil.c,v 1.8 2013/11/11 23:57:34 joerg Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <math.h>
|
||||
@ -244,6 +244,107 @@ ATF_TC_BODY(ceilf_zero_pos, tc)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* ceill(3)
|
||||
*/
|
||||
ATF_TC(ceill_basic);
|
||||
ATF_TC_HEAD(ceill_basic, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "A basic test of ceill(3)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_basic, tc)
|
||||
{
|
||||
const long double x = 0.9999999;
|
||||
const long double y = 0.0000001;
|
||||
|
||||
ATF_CHECK(fabsl(ceill(x) - 1) < SMALL_NUM);
|
||||
ATF_CHECK(fabsl(ceill(y) - 1) < SMALL_NUM);
|
||||
}
|
||||
|
||||
ATF_TC(ceill_nan);
|
||||
ATF_TC_HEAD(ceill_nan, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ceill(NaN) == NaN");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_nan, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 0.0L / 0.0L;
|
||||
|
||||
ATF_CHECK(isnan(ceill(x)) != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(ceill_inf_neg);
|
||||
ATF_TC_HEAD(ceill_inf_neg, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ceill(-Inf) == -Inf");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_inf_neg, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = -1.0L / 0.0L;
|
||||
long double y = ceill(x);
|
||||
|
||||
if (isinf(y) == 0 || signbit(y) == 0)
|
||||
atf_tc_fail_nonfatal("ceill(-Inf) != -Inf");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(ceill_inf_pos);
|
||||
ATF_TC_HEAD(ceill_inf_pos, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ceill(+Inf) == +Inf");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_inf_pos, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 1.0L / 0.0L;
|
||||
long double y = ceill(x);
|
||||
|
||||
if (isinf(y) == 0 || signbit(y) != 0)
|
||||
atf_tc_fail_nonfatal("ceill(+Inf) != +Inf");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(ceill_zero_neg);
|
||||
ATF_TC_HEAD(ceill_zero_neg, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ceill(-0.0) == -0.0");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_zero_neg, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = -0.0L;
|
||||
long double y = ceill(x);
|
||||
|
||||
if (fabsl(y) > 0.0 || signbit(y) == 0)
|
||||
atf_tc_fail_nonfatal("ceill(-0.0) != -0.0");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(ceill_zero_pos);
|
||||
ATF_TC_HEAD(ceill_zero_pos, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test ceill(+0.0) == +0.0");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(ceill_zero_pos, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 0.0L;
|
||||
long double y = ceill(x);
|
||||
|
||||
if (fabsl(y) > 0.0 || signbit(y) != 0)
|
||||
atf_tc_fail_nonfatal("ceill(+0.0) != +0.0");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* floor(3)
|
||||
*/
|
||||
@ -446,6 +547,107 @@ ATF_TC_BODY(floorf_zero_pos, tc)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* floorl(3)
|
||||
*/
|
||||
ATF_TC(floorl_basic);
|
||||
ATF_TC_HEAD(floorl_basic, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "A basic test of floorl(3)");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_basic, tc)
|
||||
{
|
||||
const long double x = 0.9999999;
|
||||
const long double y = 0.0000001;
|
||||
|
||||
ATF_CHECK(floorl(x) < SMALL_NUM);
|
||||
ATF_CHECK(floorl(y) < SMALL_NUM);
|
||||
}
|
||||
|
||||
ATF_TC(floorl_nan);
|
||||
ATF_TC_HEAD(floorl_nan, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test floorl(NaN) == NaN");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_nan, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 0.0L / 0.0L;
|
||||
|
||||
ATF_CHECK(isnan(floorl(x)) != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(floorl_inf_neg);
|
||||
ATF_TC_HEAD(floorl_inf_neg, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test floorl(-Inf) == -Inf");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_inf_neg, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = -1.0L / 0.0L;
|
||||
long double y = floorl(x);
|
||||
|
||||
if (isinf(y) == 0 || signbit(y) == 0)
|
||||
atf_tc_fail_nonfatal("floorl(-Inf) != -Inf");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(floorl_inf_pos);
|
||||
ATF_TC_HEAD(floorl_inf_pos, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test floorl(+Inf) == +Inf");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_inf_pos, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 1.0L / 0.0L;
|
||||
long double y = floorl(x);
|
||||
|
||||
if (isinf(y) == 0 || signbit(y) != 0)
|
||||
atf_tc_fail_nonfatal("floorl(+Inf) != +Inf");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(floorl_zero_neg);
|
||||
ATF_TC_HEAD(floorl_zero_neg, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test floorl(-0.0) == -0.0");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_zero_neg, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = -0.0L;
|
||||
long double y = floorl(x);
|
||||
|
||||
if (fabsl(y) > 0.0 || signbit(y) == 0)
|
||||
atf_tc_fail_nonfatal("floorl(-0.0) != -0.0");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TC(floorl_zero_pos);
|
||||
ATF_TC_HEAD(floorl_zero_pos, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test floorl(+0.0) == +0.0");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(floorl_zero_pos, tc)
|
||||
{
|
||||
#ifndef __vax__
|
||||
const long double x = 0.0L;
|
||||
long double y = floorl(x);
|
||||
|
||||
if (fabsl(y) > 0.0 || signbit(y) != 0)
|
||||
atf_tc_fail_nonfatal("floorl(+0.0) != +0.0");
|
||||
#endif
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
@ -463,6 +665,13 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, ceilf_zero_neg);
|
||||
ATF_TP_ADD_TC(tp, ceilf_zero_pos);
|
||||
|
||||
ATF_TP_ADD_TC(tp, ceill_basic);
|
||||
ATF_TP_ADD_TC(tp, ceill_nan);
|
||||
ATF_TP_ADD_TC(tp, ceill_inf_neg);
|
||||
ATF_TP_ADD_TC(tp, ceill_inf_pos);
|
||||
ATF_TP_ADD_TC(tp, ceill_zero_neg);
|
||||
ATF_TP_ADD_TC(tp, ceill_zero_pos);
|
||||
|
||||
ATF_TP_ADD_TC(tp, floor_basic);
|
||||
ATF_TP_ADD_TC(tp, floor_nan);
|
||||
ATF_TP_ADD_TC(tp, floor_inf_neg);
|
||||
@ -477,5 +686,12 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, floorf_zero_neg);
|
||||
ATF_TP_ADD_TC(tp, floorf_zero_pos);
|
||||
|
||||
ATF_TP_ADD_TC(tp, floorl_basic);
|
||||
ATF_TP_ADD_TC(tp, floorl_nan);
|
||||
ATF_TP_ADD_TC(tp, floorl_inf_neg);
|
||||
ATF_TP_ADD_TC(tp, floorl_inf_pos);
|
||||
ATF_TP_ADD_TC(tp, floorl_zero_neg);
|
||||
ATF_TP_ADD_TC(tp, floorl_zero_pos);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_round.c,v 1.3 2011/09/13 08:58:41 jruoho Exp $ */
|
||||
/* $NetBSD: t_round.c,v 1.4 2013/11/11 23:57:34 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
@ -38,6 +39,7 @@
|
||||
/* 0.5 - EPSILON */
|
||||
#define VAL 0x0.7ffffffffffffcp0
|
||||
#define VALF 0x0.7fffff8p0
|
||||
#define VALL (0.5 - LDBL_EPSILON)
|
||||
|
||||
#ifdef __vax__
|
||||
#define SMALL_NUM 1.0e-38
|
||||
@ -55,18 +57,23 @@ ATF_TC_BODY(round_dir, tc)
|
||||
{
|
||||
double a = VAL, b, c;
|
||||
float af = VALF, bf, cf;
|
||||
long double al = VALL, bl, cl;
|
||||
|
||||
b = round(a);
|
||||
bf = roundf(af);
|
||||
bl = roundl(al);
|
||||
|
||||
ATF_CHECK(fabs(b) < SMALL_NUM);
|
||||
ATF_CHECK(fabsf(bf) < SMALL_NUM);
|
||||
ATF_CHECK(fabsl(bl) < SMALL_NUM);
|
||||
|
||||
c = round(-a);
|
||||
cf = roundf(-af);
|
||||
cl = roundl(-al);
|
||||
|
||||
ATF_CHECK(fabs(c) < SMALL_NUM);
|
||||
ATF_CHECK(fabsf(cf) < SMALL_NUM);
|
||||
ATF_CHECK(fabsl(cl) < SMALL_NUM);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
|
Loading…
Reference in New Issue
Block a user