Home | History | Annotate | Line # | Download | only in libm
t_ilogb.c revision 1.6.2.3
      1  1.6.2.3  pgoyette /* $NetBSD: t_ilogb.c,v 1.6.2.3 2017/03/20 06:57:59 pgoyette Exp $ */
      2  1.6.2.2  pgoyette 
      3  1.6.2.2  pgoyette /*-
      4  1.6.2.2  pgoyette  * Copyright (c) 2016 The NetBSD Foundation, Inc.
      5  1.6.2.2  pgoyette  * All rights reserved.
      6  1.6.2.2  pgoyette  *
      7  1.6.2.2  pgoyette  * This code is derived from software contributed to The NetBSD Foundation
      8  1.6.2.2  pgoyette  * by Maya Rashish.
      9  1.6.2.2  pgoyette  *
     10  1.6.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
     11  1.6.2.2  pgoyette  * modification, are permitted provided that the following conditions
     12  1.6.2.2  pgoyette  * are met:
     13  1.6.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     14  1.6.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     15  1.6.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.6.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     17  1.6.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     18  1.6.2.2  pgoyette  *
     19  1.6.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.6.2.2  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.6.2.2  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.6.2.2  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.6.2.2  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.6.2.2  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.6.2.2  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.6.2.2  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.6.2.2  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.6.2.2  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.6.2.2  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     30  1.6.2.2  pgoyette  */
     31  1.6.2.3  pgoyette #include <sys/cdefs.h>
     32  1.6.2.3  pgoyette __RCSID("$NetBSD: t_ilogb.c,v 1.6.2.3 2017/03/20 06:57:59 pgoyette Exp $");
     33  1.6.2.2  pgoyette 
     34  1.6.2.2  pgoyette #include <atf-c.h>
     35  1.6.2.2  pgoyette #include <fenv.h>
     36  1.6.2.3  pgoyette #include <limits.h>
     37  1.6.2.2  pgoyette #include <math.h>
     38  1.6.2.2  pgoyette 
     39  1.6.2.2  pgoyette #ifndef __HAVE_FENV
     40  1.6.2.2  pgoyette 
     41  1.6.2.3  pgoyette # define ATF_CHECK_RAISED_INVALID
     42  1.6.2.3  pgoyette # define ATF_CHECK_RAISED_NOTHING
     43  1.6.2.2  pgoyette 
     44  1.6.2.2  pgoyette #else
     45  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_INVALID do { \
     46  1.6.2.2  pgoyette 	int r = fetestexcept(FE_ALL_EXCEPT); \
     47  1.6.2.2  pgoyette 	ATF_CHECK_MSG(r == FE_INVALID, "r=%#x != %#x\n", r, FE_INVALID); \
     48  1.6.2.2  pgoyette 	(void)feclearexcept(FE_ALL_EXCEPT); \
     49  1.6.2.2  pgoyette } while (/*CONSTCOND*/0)
     50  1.6.2.2  pgoyette 
     51  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_NOTHING do { \
     52  1.6.2.2  pgoyette 	int r = fetestexcept(FE_ALL_EXCEPT); \
     53  1.6.2.2  pgoyette 	ATF_CHECK_MSG(r == 0, "r=%#x != 0\n", r); \
     54  1.6.2.2  pgoyette 	(void)feclearexcept(FE_ALL_EXCEPT); \
     55  1.6.2.2  pgoyette } while (/*CONSTCOND*/0)
     56  1.6.2.2  pgoyette #endif
     57  1.6.2.2  pgoyette 
     58  1.6.2.2  pgoyette ATF_TC(ilogb);
     59  1.6.2.2  pgoyette ATF_TC_HEAD(ilogb, tc)
     60  1.6.2.2  pgoyette {
     61  1.6.2.2  pgoyette 	atf_tc_set_md_var(tc, "descr","Check ilogb family");
     62  1.6.2.2  pgoyette }
     63  1.6.2.2  pgoyette 
     64  1.6.2.2  pgoyette ATF_TC_BODY(ilogb, tc)
     65  1.6.2.2  pgoyette {
     66  1.6.2.2  pgoyette 
     67  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(0) == FP_ILOGB0);
     68  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     69  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(0) == FP_ILOGB0);
     70  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     71  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     72  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(0) == FP_ILOGB0);
     73  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     74  1.6.2.2  pgoyette #endif
     75  1.6.2.2  pgoyette 
     76  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(-0) == FP_ILOGB0);
     77  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     78  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(-0) == FP_ILOGB0);
     79  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     80  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     81  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(-0) == FP_ILOGB0);
     82  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     83  1.6.2.2  pgoyette #endif
     84  1.6.2.2  pgoyette 
     85  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(INFINITY) == INT_MAX);
     86  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     87  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(INFINITY) == INT_MAX);
     88  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     89  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     90  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(INFINITY) == INT_MAX);
     91  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     92  1.6.2.2  pgoyette #endif
     93  1.6.2.2  pgoyette 
     94  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(-INFINITY) == INT_MAX);
     95  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     96  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(-INFINITY) == INT_MAX);
     97  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     98  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     99  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(-INFINITY) == INT_MAX);
    100  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    101  1.6.2.2  pgoyette #endif
    102  1.6.2.2  pgoyette 
    103  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(1024) == 10);
    104  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    105  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(1024) == 10);
    106  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    107  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
    108  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(1024) == 10);
    109  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    110  1.6.2.2  pgoyette #endif
    111  1.6.2.2  pgoyette 
    112  1.6.2.2  pgoyette #ifndef __vax__
    113  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(NAN) == FP_ILOGBNAN);
    114  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    115  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(NAN) == FP_ILOGBNAN);
    116  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    117  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
    118  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(NAN) == FP_ILOGBNAN);
    119  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    120  1.6.2.2  pgoyette #endif
    121  1.6.2.2  pgoyette #endif
    122  1.6.2.2  pgoyette }
    123  1.6.2.2  pgoyette 
    124  1.6.2.2  pgoyette ATF_TP_ADD_TCS(tp)
    125  1.6.2.2  pgoyette {
    126  1.6.2.2  pgoyette 
    127  1.6.2.2  pgoyette 	ATF_TP_ADD_TC(tp, ilogb);
    128  1.6.2.2  pgoyette 
    129  1.6.2.2  pgoyette 	return atf_no_error();
    130  1.6.2.2  pgoyette }
    131