Home | History | Annotate | Line # | Download | only in libm
t_modf.c revision 1.2
      1  1.2  riastrad /*	$NetBSD: t_modf.c,v 1.2 2024/05/06 00:54:02 riastradh Exp $	*/
      2  1.1     joerg 
      3  1.1     joerg /*-
      4  1.1     joerg  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  1.1     joerg  * All rights reserved.
      6  1.1     joerg  *
      7  1.1     joerg  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     joerg  * by Joerg Sonnenberger.
      9  1.1     joerg  *
     10  1.1     joerg  * Redistribution and use in source and binary forms, with or without
     11  1.1     joerg  * modification, are permitted provided that the following conditions
     12  1.1     joerg  * are met:
     13  1.1     joerg  * 1. Redistributions of source code must retain the above copyright
     14  1.1     joerg  *    notice, this list of conditions and the following disclaimer.
     15  1.1     joerg  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     joerg  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     joerg  *    documentation and/or other materials provided with the distribution.
     18  1.1     joerg  *
     19  1.1     joerg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1     joerg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1     joerg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1     joerg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1     joerg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1     joerg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1     joerg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1     joerg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1     joerg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1     joerg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1     joerg  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1     joerg  */
     31  1.1     joerg 
     32  1.2  riastrad #include <sys/cdefs.h>
     33  1.2  riastrad __RCSID("$NetBSD: t_modf.c,v 1.2 2024/05/06 00:54:02 riastradh Exp $");
     34  1.2  riastrad 
     35  1.1     joerg #include <atf-c.h>
     36  1.1     joerg #include <float.h>
     37  1.1     joerg #include <math.h>
     38  1.1     joerg 
     39  1.2  riastrad __CTASSERT(FLT_RADIX == 2);
     40  1.2  riastrad 
     41  1.2  riastrad static const struct {
     42  1.2  riastrad 	float x, i, f;
     43  1.2  riastrad } casesf[] = {
     44  1.2  riastrad 	{ 0, 0, 0 },
     45  1.2  riastrad 	{ FLT_MIN, 0, FLT_MIN },
     46  1.2  riastrad 	{ 0.5, 0, 0.5 },
     47  1.2  riastrad 	{ 1 - FLT_EPSILON/2, 0, 1 - FLT_EPSILON/2 },
     48  1.2  riastrad 	{ 1, 1, 0 },
     49  1.2  riastrad 	{ 1 + FLT_EPSILON, 1, FLT_EPSILON },
     50  1.2  riastrad 	{ 0.5/FLT_EPSILON - 0.5, 0.5/FLT_EPSILON - 1, 0.5 },
     51  1.2  riastrad 	{ 0.5/FLT_EPSILON, 0.5/FLT_EPSILON, 0 },
     52  1.2  riastrad 	{ 0.5/FLT_EPSILON + 0.5, 0.5/FLT_EPSILON, 0.5 },
     53  1.2  riastrad 	{ 1/FLT_EPSILON, 1/FLT_EPSILON, 0 },
     54  1.2  riastrad };
     55  1.2  riastrad 
     56  1.2  riastrad static const struct {
     57  1.2  riastrad 	double x, i, f;
     58  1.2  riastrad } cases[] = {
     59  1.2  riastrad 	{ 0, 0, 0 },
     60  1.2  riastrad 	{ DBL_MIN, 0, DBL_MIN },
     61  1.2  riastrad 	{ 0.5, 0, 0.5 },
     62  1.2  riastrad 	{ 1 - DBL_EPSILON/2, 0, 1 - DBL_EPSILON/2 },
     63  1.2  riastrad 	{ 1, 1, 0 },
     64  1.2  riastrad 	{ 1 + DBL_EPSILON, 1, DBL_EPSILON },
     65  1.2  riastrad 	{ 1/FLT_EPSILON + 0.5, 1/FLT_EPSILON, 0.5 },
     66  1.2  riastrad 	{ 0.5/DBL_EPSILON - 0.5, 0.5/DBL_EPSILON - 1, 0.5 },
     67  1.2  riastrad 	{ 0.5/DBL_EPSILON, 0.5/DBL_EPSILON, 0 },
     68  1.2  riastrad 	{ 0.5/DBL_EPSILON + 0.5, 0.5/DBL_EPSILON, 0.5 },
     69  1.2  riastrad 	{ 1/DBL_EPSILON, 1/DBL_EPSILON, 0 },
     70  1.2  riastrad };
     71  1.2  riastrad 
     72  1.2  riastrad #ifdef __HAVE_LONG_DOUBLE
     73  1.2  riastrad static const struct {
     74  1.2  riastrad 	long double x, i, f;
     75  1.2  riastrad } casesl[] = {
     76  1.2  riastrad 	{ 0, 0, 0 },
     77  1.2  riastrad 	{ LDBL_MIN, 0, LDBL_MIN },
     78  1.2  riastrad 	{ 0.5, 0, 0.5 },
     79  1.2  riastrad 	{ 1 - LDBL_EPSILON/2, 0, 1 - LDBL_EPSILON/2 },
     80  1.2  riastrad 	{ 1, 1, 0 },
     81  1.2  riastrad 	{ 1 + LDBL_EPSILON, 1, LDBL_EPSILON },
     82  1.2  riastrad 	{ 1.0L/DBL_EPSILON + 0.5L, 1.0L/DBL_EPSILON, 0.5 },
     83  1.2  riastrad 	{ 0.5/LDBL_EPSILON - 0.5L, 0.5/LDBL_EPSILON - 1, 0.5 },
     84  1.2  riastrad 	{ 0.5/LDBL_EPSILON, 0.5/LDBL_EPSILON, 0 },
     85  1.2  riastrad 	{ 0.5/LDBL_EPSILON + 0.5L, 0.5/LDBL_EPSILON, 0.5 },
     86  1.2  riastrad 	{ 1/LDBL_EPSILON, 1/LDBL_EPSILON, 0 },
     87  1.2  riastrad };
     88  1.2  riastrad #endif	/* __HAVE_LONG_DOUBLE */
     89  1.2  riastrad 
     90  1.2  riastrad ATF_TC(modff);
     91  1.2  riastrad ATF_TC_HEAD(modff, tc)
     92  1.2  riastrad {
     93  1.2  riastrad 	atf_tc_set_md_var(tc, "descr", "modff(3)");
     94  1.2  riastrad }
     95  1.2  riastrad ATF_TC_BODY(modff, tc)
     96  1.2  riastrad {
     97  1.2  riastrad 	unsigned n;
     98  1.2  riastrad 
     99  1.2  riastrad 	for (n = 0; n < __arraycount(casesf); n++) {
    100  1.2  riastrad 		float x, i, f;
    101  1.2  riastrad 
    102  1.2  riastrad 		x = casesf[n].x;
    103  1.2  riastrad 		f = modff(x, &i);
    104  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesf[n].i,
    105  1.2  riastrad 		    "casesf[%u]: modff %g=%a"
    106  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    107  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    108  1.2  riastrad 		    n, x, x, i, i, f, f,
    109  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    110  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesf[n].f,
    111  1.2  riastrad 		    "casesf[%u]: modff %g=%a"
    112  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    113  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    114  1.2  riastrad 		    n, x, x, i, i, f, f,
    115  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    116  1.2  riastrad 
    117  1.2  riastrad 		f = modff(-x, &i);
    118  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesf[n].i,
    119  1.2  riastrad 		    "casesf[%u]: modff %g=%a"
    120  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    121  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    122  1.2  riastrad 		    n, x, x, i, i, f, f,
    123  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    124  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesf[n].f,
    125  1.2  riastrad 		    "casesf[%u]: modff %g=%a"
    126  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    127  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    128  1.2  riastrad 		    n, x, x, i, i, f, f,
    129  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    130  1.2  riastrad 	}
    131  1.2  riastrad 
    132  1.2  riastrad #ifdef INFINITY
    133  1.2  riastrad 	{
    134  1.2  riastrad 		float x, i, f;
    135  1.2  riastrad 
    136  1.2  riastrad 		x = INFINITY;
    137  1.2  riastrad 		f = modff(x, &i);
    138  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    139  1.2  riastrad 		    "modff +inf returned integer %g=%a, frac %g=%a",
    140  1.2  riastrad 		    i, i, f, f);
    141  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    142  1.2  riastrad 		    "modff +inf returned integer %g=%a, frac %g=%a",
    143  1.2  riastrad 		    i, i, f, f);
    144  1.2  riastrad 
    145  1.2  riastrad 		x = -INFINITY;
    146  1.2  riastrad 		f = modff(x, &i);
    147  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    148  1.2  riastrad 		    "modff -inf returned integer %g=%a, frac %g=%a",
    149  1.2  riastrad 		    i, i, f, f);
    150  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    151  1.2  riastrad 		    "modff -inf returned integer %g=%a, frac %g=%a",
    152  1.2  riastrad 		    i, i, f, f);
    153  1.2  riastrad 	}
    154  1.2  riastrad #endif	/* INFINITY */
    155  1.2  riastrad 
    156  1.2  riastrad #ifdef NAN
    157  1.2  riastrad 	{
    158  1.2  riastrad 		float x, i, f;
    159  1.2  riastrad 
    160  1.2  riastrad 		x = NAN;
    161  1.2  riastrad 		f = modff(x, &i);
    162  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    163  1.2  riastrad 		    "modff NaN returned integer %g=%a, frac %g=%a",
    164  1.2  riastrad 		    i, i, f, f);
    165  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    166  1.2  riastrad 		    "modff NaN returned integer %g=%a, frac %g=%a",
    167  1.2  riastrad 		    i, i, f, f);
    168  1.2  riastrad 	}
    169  1.2  riastrad #endif	/* NAN */
    170  1.2  riastrad }
    171  1.2  riastrad 
    172  1.1     joerg ATF_TC(modf);
    173  1.1     joerg ATF_TC_HEAD(modf, tc)
    174  1.1     joerg {
    175  1.2  riastrad 	atf_tc_set_md_var(tc, "descr", "modf(3)");
    176  1.1     joerg }
    177  1.2  riastrad ATF_TC_BODY(modf, tc)
    178  1.2  riastrad {
    179  1.2  riastrad 	unsigned n;
    180  1.2  riastrad 
    181  1.2  riastrad 	for (n = 0; n < __arraycount(casesf); n++) {
    182  1.2  riastrad 		double x, i, f;
    183  1.2  riastrad 
    184  1.2  riastrad 		x = casesf[n].x;
    185  1.2  riastrad 		f = modf(x, &i);
    186  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesf[n].i,
    187  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    188  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    189  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    190  1.2  riastrad 		    n, x, x, i, i, f, f,
    191  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    192  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesf[n].f,
    193  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    194  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    195  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    196  1.2  riastrad 		    n, x, x, i, i, f, f,
    197  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    198  1.2  riastrad 
    199  1.2  riastrad 		f = modf(-x, &i);
    200  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesf[n].i,
    201  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    202  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    203  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    204  1.2  riastrad 		    n, x, x, i, i, f, f,
    205  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    206  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesf[n].f,
    207  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    208  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    209  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    210  1.2  riastrad 		    n, x, x, i, i, f, f,
    211  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    212  1.2  riastrad 	}
    213  1.2  riastrad 
    214  1.2  riastrad 	for (n = 0; n < __arraycount(cases); n++) {
    215  1.2  riastrad 		double x, i, f;
    216  1.2  riastrad 
    217  1.2  riastrad 		x = cases[n].x;
    218  1.2  riastrad 		f = modf(x, &i);
    219  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, cases[n].i,
    220  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    221  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    222  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    223  1.2  riastrad 		    n, x, x, i, i, f, f,
    224  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    225  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, cases[n].f,
    226  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    227  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    228  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    229  1.2  riastrad 		    n, x, x, i, i, f, f,
    230  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    231  1.1     joerg 
    232  1.2  riastrad 		f = modf(-x, &i);
    233  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -cases[n].i,
    234  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    235  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    236  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    237  1.2  riastrad 		    n, x, x, i, i, f, f,
    238  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    239  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -cases[n].f,
    240  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    241  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    242  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    243  1.2  riastrad 		    n, x, x, i, i, f, f,
    244  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    245  1.2  riastrad 	}
    246  1.2  riastrad 
    247  1.2  riastrad #ifdef INFINITY
    248  1.2  riastrad 	{
    249  1.2  riastrad 		double x, i, f;
    250  1.2  riastrad 
    251  1.2  riastrad 		x = INFINITY;
    252  1.2  riastrad 		f = modf(x, &i);
    253  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    254  1.2  riastrad 		    "modf +inf returned integer %g=%a, frac %g=%a",
    255  1.2  riastrad 		    i, i, f, f);
    256  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    257  1.2  riastrad 		    "modf +inf returned integer %g=%a, frac %g=%a",
    258  1.2  riastrad 		    i, i, f, f);
    259  1.2  riastrad 
    260  1.2  riastrad 		x = -INFINITY;
    261  1.2  riastrad 		f = modf(x, &i);
    262  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    263  1.2  riastrad 		    "modf -inf returned integer %g=%a, frac %g=%a",
    264  1.2  riastrad 		    i, i, f, f);
    265  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    266  1.2  riastrad 		    "modf -inf returned integer %g=%a, frac %g=%a",
    267  1.2  riastrad 		    i, i, f, f);
    268  1.2  riastrad 	}
    269  1.2  riastrad #endif	/* INFINITY */
    270  1.2  riastrad 
    271  1.2  riastrad #ifdef NAN
    272  1.2  riastrad 	{
    273  1.2  riastrad 		double x, i, f;
    274  1.2  riastrad 
    275  1.2  riastrad 		x = NAN;
    276  1.2  riastrad 		f = modf(x, &i);
    277  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    278  1.2  riastrad 		    "modf NaN returned integer %g=%a, frac %g=%a",
    279  1.2  riastrad 		    i, i, f, f);
    280  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    281  1.2  riastrad 		    "modf NaN returned integer %g=%a, frac %g=%a",
    282  1.2  riastrad 		    i, i, f, f);
    283  1.2  riastrad 	}
    284  1.2  riastrad #endif	/* NAN */
    285  1.2  riastrad }
    286  1.2  riastrad 
    287  1.2  riastrad ATF_TC(modfl);
    288  1.2  riastrad ATF_TC_HEAD(modfl, tc)
    289  1.2  riastrad {
    290  1.2  riastrad 	atf_tc_set_md_var(tc, "descr", "modfl(3)");
    291  1.2  riastrad }
    292  1.2  riastrad ATF_TC_BODY(modfl, tc)
    293  1.1     joerg {
    294  1.2  riastrad 	unsigned n;
    295  1.2  riastrad 
    296  1.2  riastrad 	for (n = 0; n < __arraycount(casesf); n++) {
    297  1.2  riastrad 		long double x, i, f;
    298  1.2  riastrad 
    299  1.2  riastrad 		x = casesf[n].x;
    300  1.2  riastrad 		f = modfl(x, &i);
    301  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesf[n].i,
    302  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    303  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    304  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    305  1.2  riastrad 		    n, x, x, i, i, f, f,
    306  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    307  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesf[n].f,
    308  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    309  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    310  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    311  1.2  riastrad 		    n, x, x, i, i, f, f,
    312  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    313  1.2  riastrad 
    314  1.2  riastrad 		f = modfl(-x, &i);
    315  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesf[n].i,
    316  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    317  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    318  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    319  1.2  riastrad 		    n, x, x, i, i, f, f,
    320  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    321  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesf[n].f,
    322  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    323  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    324  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    325  1.2  riastrad 		    n, x, x, i, i, f, f,
    326  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    327  1.2  riastrad 	}
    328  1.2  riastrad 
    329  1.2  riastrad 	for (n = 0; n < __arraycount(cases); n++) {
    330  1.2  riastrad 		long double x, i, f;
    331  1.2  riastrad 
    332  1.2  riastrad 		x = cases[n].x;
    333  1.2  riastrad 		f = modfl(x, &i);
    334  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, cases[n].i,
    335  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    336  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    337  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    338  1.2  riastrad 		    n, x, x, i, i, f, f,
    339  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    340  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, cases[n].f,
    341  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    342  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    343  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    344  1.2  riastrad 		    n, x, x, i, i, f, f,
    345  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    346  1.2  riastrad 
    347  1.2  riastrad 		f = modfl(-x, &i);
    348  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -cases[n].i,
    349  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    350  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    351  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    352  1.2  riastrad 		    n, x, x, i, i, f, f,
    353  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    354  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -cases[n].f,
    355  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    356  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    357  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    358  1.2  riastrad 		    n, x, x, i, i, f, f,
    359  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    360  1.2  riastrad 	}
    361  1.2  riastrad 
    362  1.2  riastrad #ifdef __HAVE_LONG_DOUBLE
    363  1.2  riastrad 	for (n = 0; n < __arraycount(casesl); n++) {
    364  1.2  riastrad 		long double x, i, f;
    365  1.2  riastrad 
    366  1.2  riastrad 		x = casesl[n].x;
    367  1.2  riastrad 		f = modfl(x, &i);
    368  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesl[n].i,
    369  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    370  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    371  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    372  1.2  riastrad 		    n, x, x, i, i, f, f,
    373  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    374  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesl[n].f,
    375  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    376  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    377  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    378  1.2  riastrad 		    n, x, x, i, i, f, f,
    379  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    380  1.2  riastrad 
    381  1.2  riastrad 		f = modfl(-x, &i);
    382  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesl[n].i,
    383  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    384  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    385  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    386  1.2  riastrad 		    n, x, x, i, i, f, f,
    387  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    388  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesl[n].f,
    389  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    390  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    391  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    392  1.2  riastrad 		    n, x, x, i, i, f, f,
    393  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    394  1.2  riastrad 	}
    395  1.2  riastrad #endif	/* __HAVE_LONG_DOUBLE */
    396  1.2  riastrad 
    397  1.2  riastrad #ifdef INFINITY
    398  1.2  riastrad 	{
    399  1.2  riastrad 		long double x, i, f;
    400  1.2  riastrad 
    401  1.2  riastrad 		x = INFINITY;
    402  1.2  riastrad 		f = modfl(x, &i);
    403  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    404  1.2  riastrad 		    "modfl +inf returned integer %Lg=%La, frac %Lg=%La",
    405  1.2  riastrad 		    i, i, f, f);
    406  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    407  1.2  riastrad 		    "modfl +inf returned integer %Lg=%La, frac %Lg=%La",
    408  1.2  riastrad 		    i, i, f, f);
    409  1.2  riastrad 
    410  1.2  riastrad 		x = -INFINITY;
    411  1.2  riastrad 		f = modfl(x, &i);
    412  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    413  1.2  riastrad 		    "modfl -inf returned integer %Lg=%La, frac %Lg=%La",
    414  1.2  riastrad 		    i, i, f, f);
    415  1.2  riastrad 		ATF_CHECK_MSG(isinf(i),
    416  1.2  riastrad 		    "modfl -inf returned integer %Lg=%La, frac %Lg=%La",
    417  1.2  riastrad 		    i, i, f, f);
    418  1.2  riastrad 	}
    419  1.2  riastrad #endif
    420  1.2  riastrad 
    421  1.2  riastrad #ifdef NAN
    422  1.2  riastrad 	{
    423  1.2  riastrad 		long double x, i, f;
    424  1.2  riastrad 
    425  1.2  riastrad 		x = NAN;
    426  1.2  riastrad 		f = modfl(x, &i);
    427  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    428  1.2  riastrad 		    "modfl NaN returned integer %Lg=%La, frac %Lg=%La",
    429  1.2  riastrad 		    i, i, f, f);
    430  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    431  1.2  riastrad 		    "modfl NaN returned integer %Lg=%La, frac %Lg=%La",
    432  1.2  riastrad 		    i, i, f, f);
    433  1.2  riastrad 	}
    434  1.2  riastrad #endif
    435  1.1     joerg }
    436  1.1     joerg 
    437  1.1     joerg ATF_TP_ADD_TCS(tp)
    438  1.1     joerg {
    439  1.1     joerg 
    440  1.2  riastrad 	ATF_TP_ADD_TC(tp, modff);
    441  1.1     joerg 	ATF_TP_ADD_TC(tp, modf);
    442  1.2  riastrad 	ATF_TP_ADD_TC(tp, modfl);
    443  1.1     joerg 
    444  1.1     joerg 	return atf_no_error();
    445  1.1     joerg }
    446