Add modfl(3). From FreeBSD.

This commit is contained in:
joerg 2014-06-16 12:54:42 +00:00
parent 16bf2a1c98
commit 13b8fa7d71
9 changed files with 202 additions and 8 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1894 2014/05/28 11:32:50 tron Exp $
# $NetBSD: mi,v 1.1895 2014/06/16 12:54:42 joerg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -7960,6 +7960,8 @@
./usr/share/man/cat3/mktime.0 comp-c-catman .cat
./usr/share/man/cat3/mktime_z.0 comp-c-catman .cat
./usr/share/man/cat3/modf.0 comp-c-catman .cat
./usr/share/man/cat3/modff.0 comp-c-catman .cat
./usr/share/man/cat3/modfl.0 comp-c-catman .cat
./usr/share/man/cat3/moncontrol.0 comp-c-catman .cat
./usr/share/man/cat3/monstartup.0 comp-c-catman .cat
./usr/share/man/cat3/move.0 comp-c-catman .cat
@ -14745,6 +14747,8 @@
./usr/share/man/html3/mktime.html comp-c-htmlman html
./usr/share/man/html3/mktime_z.html comp-c-htmlman html
./usr/share/man/html3/modf.html comp-c-htmlman html
./usr/share/man/html3/modff.html comp-c-htmlman html
./usr/share/man/html3/modfl.html comp-c-htmlman html
./usr/share/man/html3/moncontrol.html comp-c-htmlman html
./usr/share/man/html3/monstartup.html comp-c-htmlman html
./usr/share/man/html3/move.html comp-c-htmlman html
@ -21516,6 +21520,8 @@
./usr/share/man/man3/mktime.3 comp-c-man .man
./usr/share/man/man3/mktime_z.3 comp-c-man .man
./usr/share/man/man3/modf.3 comp-c-man .man
./usr/share/man/man3/modff.3 comp-c-man .man
./usr/share/man/man3/modfl.3 comp-c-man .man
./usr/share/man/man3/moncontrol.3 comp-c-man .man
./usr/share/man/man3/monstartup.3 comp-c-man .man
./usr/share/man/man3/move.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.60 2014/04/29 06:29:02 uebayasi Exp $
# $NetBSD: mi,v 1.61 2014/06/16 12:54:42 joerg Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib
@ -2043,6 +2043,7 @@
./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libm/t_modf.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_log.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_pow.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_precision.debug tests-lib-debug debug,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.571 2014/05/31 20:26:51 christos Exp $
# $NetBSD: mi,v 1.572 2014/06/16 12:54:43 joerg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -2841,6 +2841,7 @@
./usr/tests/lib/libm/t_ldexp tests-lib-tests atf
./usr/tests/lib/libm/t_libm tests-obsolete obsolete
./usr/tests/lib/libm/t_log tests-lib-tests atf
./usr/tests/lib/libm/t_modf tests-lib-tests atf
./usr/tests/lib/libm/t_pow tests-lib-tests atf
./usr/tests/lib/libm/t_precision tests-lib-tests atf
./usr/tests/lib/libm/t_round tests-lib-tests atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.159 2014/05/18 10:47:03 martin Exp $
# $NetBSD: Makefile,v 1.160 2014/06/16 12:54:43 joerg Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@ -178,7 +178,7 @@ COMMON_SRCS+= b_exp.c b_log.c b_tgamma.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_matherr.c s_modff.c s_modfl.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_roundl.c s_scalbn.c \
s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c s_sin.c \
@ -311,6 +311,8 @@ MLINKS+=j0.3 j0f.3 j0.3 j1.3 j0.3 j1f.3 j0.3 jn.3 j0.3 jnf.3 \
MLINKS+=lgamma.3 lgammaf.3 lgamma.3 lgamma_r.3 lgamma.3 lgammaf_r.3 \
lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 gamma_r.3 \
lgamma.3 gammaf_r.3 lgamma.3 tgamma.3 lgamma.3 tgammaf.3
MLINKS+=modf.3 modff.3 \
modf.3 modfl.3
MLINKS+=nextafter.3 nextafterf.3 \
nextafter.3 nextafterl.3 \
nextafter.3 nexttoward.3

View File

@ -1,4 +1,4 @@
/* $NetBSD: namespace.h,v 1.10 2013/11/19 19:24:34 joerg Exp $ */
/* $NetBSD: namespace.h,v 1.11 2014/06/16 12:54:43 joerg Exp $ */
#define atan2 _atan2
#define atan2f _atan2f
@ -52,6 +52,7 @@
#define floorl _floorl
#define roundl _roundl
#define fmodl _fmodl
#define modfl _modfl
#define truncl _truncl
#define exp2l _exp2l

View File

@ -12,7 +12,7 @@
#include <sys/cdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: s_modf.c,v 1.14 2010/01/27 14:07:41 drochner Exp $");
__RCSID("$NetBSD: s_modf.c,v 1.15 2014/06/16 12:54:43 joerg Exp $");
#endif
/*
@ -30,6 +30,11 @@ __RCSID("$NetBSD: s_modf.c,v 1.14 2010/01/27 14:07:41 drochner Exp $");
static const double one = 1.0;
#ifndef __HAVE_LONG_DOUBLE
__strong_alias(_modfl, modf)
__weak_alias(modfl, modf)
#endif
double
modf(double x, double *iptr)
{

109
lib/libm/src/s_modfl.c Normal file
View File

@ -0,0 +1,109 @@
/*-
* Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
* 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, 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* Derived from s_modf.c, which has the following Copyright:
* ====================================================
* 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.
* ====================================================
*
* $FreeBSD: head/lib/msun/src/s_modfl.c 165855 2007-01-07 07:54:21Z das $
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: s_modfl.c,v 1.1 2014/06/16 12:54:43 joerg Exp $");
#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(modfl, _modfl)
#endif
#if LDBL_MANL_SIZE > 32
#define MASK ((uint64_t)-1)
#else
#define MASK ((uint32_t)-1)
#endif
/* Return the last n bits of a word, representing the fractional part. */
#define GETFRAC(bits, n) ((bits) & ~(MASK << (n)))
/* The number of fraction bits in manh, not counting the integer bit */
#define HIBITS (LDBL_MANT_DIG - EXT_FRACHBITS)
static const long double zero[] = { 0.0L, -0.0L };
long double
modfl(long double x, long double *iptr)
{
union ieee_ext_u ux = { .extu_ld = x, };
int e = ux.extu_exp - LDBL_MAX_EXP + 1;
if (e < HIBITS) { /* Integer part is in manh. */
if (e < 0) { /* |x|<1 */
*iptr = zero[ux.extu_sign];
return (x);
} else {
if ((GETFRAC(ux.extu_frach, HIBITS - 1 - e) |
ux.extu_fracl) == 0) { /* X is an integer. */
*iptr = x;
return (zero[ux.extu_sign]);
} else {
/* Clear all but the top e+1 bits. */
ux.extu_frach >>= HIBITS - 1 - e;
ux.extu_frach <<= HIBITS - 1 - e;
ux.extu_fracl = 0;
*iptr = ux.extu_ld;
return (x - ux.extu_ld);
}
}
} else if (e >= LDBL_MANT_DIG - 1) { /* x has no fraction part. */
*iptr = x;
if (x != x) /* Handle NaNs. */
return (x);
return (zero[ux.extu_sign]);
} else { /* Fraction part is in manl. */
if (GETFRAC(ux.extu_fracl, LDBL_MANT_DIG - 1 - e) == 0) {
/* x is integral. */
*iptr = x;
return (zero[ux.extu_sign]);
} else {
/* Clear all but the top e+1 bits. */
ux.extu_fracl >>= LDBL_MANT_DIG - 1 - e;
ux.extu_fracl <<= LDBL_MANT_DIG - 1 - e;
*iptr = ux.extu_ld;
return (x - ux.extu_ld);
}
}
}
#endif /* __HAVE_LONG_DOUBLE */

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.24 2014/05/18 10:47:38 martin Exp $
# $NetBSD: Makefile,v 1.25 2014/06/16 12:54:43 joerg Exp $
.include <bsd.own.mk>
@ -27,6 +27,7 @@ TESTS_C+= t_fmod
TESTS_C+= t_infinity
TESTS_C+= t_ldexp
TESTS_C+= t_log
TESTS_C+= t_modf
TESTS_C+= t_pow
TESTS_C+= t_precision
TESTS_C+= t_round

68
tests/lib/libm/t_modf.c Normal file
View File

@ -0,0 +1,68 @@
/* $NetBSD: t_modf.c,v 1.1 2014/06/16 12:54:43 joerg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Joerg Sonnenberger.
*
* 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, 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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 <atf-c.h>
#include <float.h>
#include <math.h>
ATF_TC(modf);
ATF_TC_HEAD(modf, tc)
{
atf_tc_set_md_var(tc, "descr","Check modf family");
}
ATF_TC_BODY(modf, tc)
{
float basef;
double base;
long double basel;
ATF_CHECK(modff(1.0, &basef) == 0.0);
ATF_CHECK(basef == 1.0);
ATF_CHECK(modf(1.0, &base) == 0.0);
ATF_CHECK(base == 1.0);
ATF_CHECK(modfl(1.0, &basel) == 0.0);
ATF_CHECK(basel == 1.0);
ATF_CHECK(modff(-1 - FLT_EPSILON, &basef) == -FLT_EPSILON);
ATF_CHECK(basef == -1.0);
ATF_CHECK(modf(-1 - DBL_EPSILON, &base) == -DBL_EPSILON);
ATF_CHECK(base == -1.0);
ATF_CHECK(modfl(-1 - LDBL_EPSILON, &basel) == -LDBL_EPSILON);
ATF_CHECK(basel == -1.0);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, modf);
return atf_no_error();
}