Home | History | Annotate | Line # | Download | only in libm
      1  1.6  riastrad /*	$NetBSD: t_modf.c,v 1.6 2024/05/15 00:02:57 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.6  riastrad __RCSID("$NetBSD: t_modf.c,v 1.6 2024/05/15 00:02:57 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.4  riastrad 	if (isinf(INFINITY)) {
    133  1.2  riastrad 		float x, i, f;
    134  1.2  riastrad 
    135  1.2  riastrad 		x = INFINITY;
    136  1.2  riastrad 		f = modff(x, &i);
    137  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    138  1.2  riastrad 		    "modff +inf returned integer %g=%a, frac %g=%a",
    139  1.2  riastrad 		    i, i, f, f);
    140  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i > 0,
    141  1.2  riastrad 		    "modff +inf returned integer %g=%a, frac %g=%a",
    142  1.2  riastrad 		    i, i, f, f);
    143  1.2  riastrad 
    144  1.2  riastrad 		x = -INFINITY;
    145  1.2  riastrad 		f = modff(x, &i);
    146  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    147  1.2  riastrad 		    "modff -inf returned integer %g=%a, frac %g=%a",
    148  1.2  riastrad 		    i, i, f, f);
    149  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i < 0,
    150  1.2  riastrad 		    "modff -inf returned integer %g=%a, frac %g=%a",
    151  1.2  riastrad 		    i, i, f, f);
    152  1.2  riastrad 	}
    153  1.2  riastrad 
    154  1.2  riastrad #ifdef NAN
    155  1.2  riastrad 	{
    156  1.2  riastrad 		float x, i, f;
    157  1.2  riastrad 
    158  1.2  riastrad 		x = NAN;
    159  1.2  riastrad 		f = modff(x, &i);
    160  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    161  1.2  riastrad 		    "modff NaN returned integer %g=%a, frac %g=%a",
    162  1.2  riastrad 		    i, i, f, f);
    163  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    164  1.2  riastrad 		    "modff NaN returned integer %g=%a, frac %g=%a",
    165  1.2  riastrad 		    i, i, f, f);
    166  1.2  riastrad 	}
    167  1.2  riastrad #endif	/* NAN */
    168  1.2  riastrad }
    169  1.2  riastrad 
    170  1.1     joerg ATF_TC(modf);
    171  1.1     joerg ATF_TC_HEAD(modf, tc)
    172  1.1     joerg {
    173  1.2  riastrad 	atf_tc_set_md_var(tc, "descr", "modf(3)");
    174  1.1     joerg }
    175  1.2  riastrad ATF_TC_BODY(modf, tc)
    176  1.2  riastrad {
    177  1.2  riastrad 	unsigned n;
    178  1.2  riastrad 
    179  1.2  riastrad 	for (n = 0; n < __arraycount(casesf); n++) {
    180  1.2  riastrad 		double x, i, f;
    181  1.2  riastrad 
    182  1.2  riastrad 		x = casesf[n].x;
    183  1.2  riastrad 		f = modf(x, &i);
    184  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesf[n].i,
    185  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    186  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    187  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    188  1.2  riastrad 		    n, x, x, i, i, f, f,
    189  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    190  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesf[n].f,
    191  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    192  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    193  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    194  1.2  riastrad 		    n, x, x, i, i, f, f,
    195  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    196  1.2  riastrad 
    197  1.2  riastrad 		f = modf(-x, &i);
    198  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesf[n].i,
    199  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    200  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    201  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    202  1.2  riastrad 		    n, x, x, i, i, f, f,
    203  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    204  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesf[n].f,
    205  1.2  riastrad 		    "casesf[%u]: modf %g=%a"
    206  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    207  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    208  1.2  riastrad 		    n, x, x, i, i, f, f,
    209  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    210  1.2  riastrad 	}
    211  1.2  riastrad 
    212  1.2  riastrad 	for (n = 0; n < __arraycount(cases); n++) {
    213  1.2  riastrad 		double x, i, f;
    214  1.2  riastrad 
    215  1.2  riastrad 		x = cases[n].x;
    216  1.2  riastrad 		f = modf(x, &i);
    217  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, cases[n].i,
    218  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    219  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    220  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    221  1.2  riastrad 		    n, x, x, i, i, f, f,
    222  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    223  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, cases[n].f,
    224  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    225  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    226  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    227  1.2  riastrad 		    n, x, x, i, i, f, f,
    228  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    229  1.1     joerg 
    230  1.2  riastrad 		f = modf(-x, &i);
    231  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -cases[n].i,
    232  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    233  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    234  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    235  1.2  riastrad 		    n, x, x, i, i, f, f,
    236  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    237  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -cases[n].f,
    238  1.2  riastrad 		    "cases[%u]: modf %g=%a"
    239  1.2  riastrad 		    " returned integer %g=%a, frac %g=%a;"
    240  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    241  1.2  riastrad 		    n, x, x, i, i, f, f,
    242  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    243  1.2  riastrad 	}
    244  1.2  riastrad 
    245  1.4  riastrad 	if (isinf(INFINITY)) {
    246  1.2  riastrad 		double x, i, f;
    247  1.2  riastrad 
    248  1.2  riastrad 		x = INFINITY;
    249  1.2  riastrad 		f = modf(x, &i);
    250  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    251  1.2  riastrad 		    "modf +inf returned integer %g=%a, frac %g=%a",
    252  1.2  riastrad 		    i, i, f, f);
    253  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i > 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 
    257  1.2  riastrad 		x = -INFINITY;
    258  1.2  riastrad 		f = modf(x, &i);
    259  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    260  1.2  riastrad 		    "modf -inf returned integer %g=%a, frac %g=%a",
    261  1.2  riastrad 		    i, i, f, f);
    262  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i < 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 	}
    266  1.2  riastrad 
    267  1.2  riastrad #ifdef NAN
    268  1.2  riastrad 	{
    269  1.2  riastrad 		double x, i, f;
    270  1.2  riastrad 
    271  1.2  riastrad 		x = NAN;
    272  1.2  riastrad 		f = modf(x, &i);
    273  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    274  1.2  riastrad 		    "modf NaN returned integer %g=%a, frac %g=%a",
    275  1.2  riastrad 		    i, i, f, f);
    276  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    277  1.2  riastrad 		    "modf NaN returned integer %g=%a, frac %g=%a",
    278  1.2  riastrad 		    i, i, f, f);
    279  1.2  riastrad 	}
    280  1.2  riastrad #endif	/* NAN */
    281  1.2  riastrad }
    282  1.2  riastrad 
    283  1.2  riastrad ATF_TC(modfl);
    284  1.2  riastrad ATF_TC_HEAD(modfl, tc)
    285  1.2  riastrad {
    286  1.2  riastrad 	atf_tc_set_md_var(tc, "descr", "modfl(3)");
    287  1.2  riastrad }
    288  1.2  riastrad ATF_TC_BODY(modfl, tc)
    289  1.1     joerg {
    290  1.2  riastrad 	unsigned n;
    291  1.2  riastrad 
    292  1.2  riastrad 	for (n = 0; n < __arraycount(casesf); n++) {
    293  1.2  riastrad 		long double x, i, f;
    294  1.2  riastrad 
    295  1.2  riastrad 		x = casesf[n].x;
    296  1.2  riastrad 		f = modfl(x, &i);
    297  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesf[n].i,
    298  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    299  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    300  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    301  1.2  riastrad 		    n, x, x, i, i, f, f,
    302  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    303  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesf[n].f,
    304  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    305  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    306  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    307  1.2  riastrad 		    n, x, x, i, i, f, f,
    308  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    309  1.2  riastrad 
    310  1.2  riastrad 		f = modfl(-x, &i);
    311  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesf[n].i,
    312  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    313  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    314  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    315  1.2  riastrad 		    n, x, x, i, i, f, f,
    316  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    317  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesf[n].f,
    318  1.2  riastrad 		    "casesf[%u]: modfl %Lg=%La"
    319  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    320  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    321  1.2  riastrad 		    n, x, x, i, i, f, f,
    322  1.2  riastrad 		    casesf[n].i, casesf[n].i, casesf[n].f, casesf[n].f);
    323  1.2  riastrad 	}
    324  1.2  riastrad 
    325  1.2  riastrad 	for (n = 0; n < __arraycount(cases); n++) {
    326  1.2  riastrad 		long double x, i, f;
    327  1.2  riastrad 
    328  1.2  riastrad 		x = cases[n].x;
    329  1.2  riastrad 		f = modfl(x, &i);
    330  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, cases[n].i,
    331  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    332  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    333  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    334  1.2  riastrad 		    n, x, x, i, i, f, f,
    335  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    336  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, cases[n].f,
    337  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    338  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    339  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    340  1.2  riastrad 		    n, x, x, i, i, f, f,
    341  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    342  1.2  riastrad 
    343  1.2  riastrad 		f = modfl(-x, &i);
    344  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -cases[n].i,
    345  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    346  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    347  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    348  1.2  riastrad 		    n, x, x, i, i, f, f,
    349  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    350  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -cases[n].f,
    351  1.2  riastrad 		    "cases[%u]: modfl %Lg=%La"
    352  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    353  1.2  riastrad 		    " expected integer %g=%a, frac %g=%a",
    354  1.2  riastrad 		    n, x, x, i, i, f, f,
    355  1.2  riastrad 		    cases[n].i, cases[n].i, cases[n].f, cases[n].f);
    356  1.2  riastrad 	}
    357  1.2  riastrad 
    358  1.2  riastrad #ifdef __HAVE_LONG_DOUBLE
    359  1.2  riastrad 	for (n = 0; n < __arraycount(casesl); n++) {
    360  1.2  riastrad 		long double x, i, f;
    361  1.2  riastrad 
    362  1.2  riastrad 		x = casesl[n].x;
    363  1.2  riastrad 		f = modfl(x, &i);
    364  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, casesl[n].i,
    365  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    366  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    367  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    368  1.2  riastrad 		    n, x, x, i, i, f, f,
    369  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    370  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, casesl[n].f,
    371  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    372  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    373  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    374  1.2  riastrad 		    n, x, x, i, i, f, f,
    375  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    376  1.2  riastrad 
    377  1.2  riastrad 		f = modfl(-x, &i);
    378  1.2  riastrad 		ATF_CHECK_EQ_MSG(i, -casesl[n].i,
    379  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    380  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    381  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    382  1.2  riastrad 		    n, x, x, i, i, f, f,
    383  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    384  1.2  riastrad 		ATF_CHECK_EQ_MSG(f, -casesl[n].f,
    385  1.2  riastrad 		    "casesl[%u]: modfl %Lg=%La"
    386  1.2  riastrad 		    " returned integer %Lg=%La, frac %Lg=%La;"
    387  1.2  riastrad 		    " expected integer %Lg=%La, frac %Lg=%La",
    388  1.2  riastrad 		    n, x, x, i, i, f, f,
    389  1.2  riastrad 		    casesl[n].i, casesl[n].i, casesl[n].f, casesl[n].f);
    390  1.2  riastrad 	}
    391  1.2  riastrad #endif	/* __HAVE_LONG_DOUBLE */
    392  1.2  riastrad 
    393  1.4  riastrad 	if (isinf(INFINITY)) {
    394  1.2  riastrad 		long double x, i, f;
    395  1.2  riastrad 
    396  1.2  riastrad 		x = INFINITY;
    397  1.2  riastrad 		f = modfl(x, &i);
    398  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    399  1.2  riastrad 		    "modfl +inf returned integer %Lg=%La, frac %Lg=%La",
    400  1.2  riastrad 		    i, i, f, f);
    401  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i > 0,
    402  1.2  riastrad 		    "modfl +inf returned integer %Lg=%La, frac %Lg=%La",
    403  1.2  riastrad 		    i, i, f, f);
    404  1.2  riastrad 
    405  1.2  riastrad 		x = -INFINITY;
    406  1.2  riastrad 		f = modfl(x, &i);
    407  1.2  riastrad 		ATF_CHECK_MSG(f == 0,
    408  1.2  riastrad 		    "modfl -inf returned integer %Lg=%La, frac %Lg=%La",
    409  1.2  riastrad 		    i, i, f, f);
    410  1.3  riastrad 		ATF_CHECK_MSG(isinf(i) && i < 0,
    411  1.2  riastrad 		    "modfl -inf returned integer %Lg=%La, frac %Lg=%La",
    412  1.2  riastrad 		    i, i, f, f);
    413  1.2  riastrad 	}
    414  1.2  riastrad 
    415  1.2  riastrad #ifdef NAN
    416  1.2  riastrad 	{
    417  1.2  riastrad 		long double x, i, f;
    418  1.2  riastrad 
    419  1.2  riastrad 		x = NAN;
    420  1.2  riastrad 		f = modfl(x, &i);
    421  1.2  riastrad 		ATF_CHECK_MSG(isnan(f),
    422  1.2  riastrad 		    "modfl NaN returned integer %Lg=%La, frac %Lg=%La",
    423  1.2  riastrad 		    i, i, f, f);
    424  1.2  riastrad 		ATF_CHECK_MSG(isnan(i),
    425  1.2  riastrad 		    "modfl NaN returned integer %Lg=%La, frac %Lg=%La",
    426  1.2  riastrad 		    i, i, f, f);
    427  1.2  riastrad 	}
    428  1.4  riastrad #endif	/* NAN */
    429  1.1     joerg }
    430  1.1     joerg 
    431  1.1     joerg ATF_TP_ADD_TCS(tp)
    432  1.1     joerg {
    433  1.1     joerg 
    434  1.2  riastrad 	ATF_TP_ADD_TC(tp, modff);
    435  1.1     joerg 	ATF_TP_ADD_TC(tp, modf);
    436  1.2  riastrad 	ATF_TP_ADD_TC(tp, modfl);
    437  1.1     joerg 
    438  1.1     joerg 	return atf_no_error();
    439  1.1     joerg }
    440