Home | History | Annotate | Line # | Download | only in libm
t_ilogb.c revision 1.6.2.2
      1  1.6.2.2  pgoyette /* $NetBSD: t_ilogb.c,v 1.6.2.2 2016/09/14 03:04:19 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.2  pgoyette 
     32  1.6.2.2  pgoyette #include <atf-c.h>
     33  1.6.2.2  pgoyette #include <fenv.h>
     34  1.6.2.2  pgoyette #include <math.h>
     35  1.6.2.2  pgoyette 
     36  1.6.2.2  pgoyette #ifndef __HAVE_FENV
     37  1.6.2.2  pgoyette 
     38  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_INVALID
     39  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_NOTHING
     40  1.6.2.2  pgoyette 
     41  1.6.2.2  pgoyette #else
     42  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_INVALID do { \
     43  1.6.2.2  pgoyette 	int r = fetestexcept(FE_ALL_EXCEPT); \
     44  1.6.2.2  pgoyette 	ATF_CHECK_MSG(r == FE_INVALID, "r=%#x != %#x\n", r, FE_INVALID); \
     45  1.6.2.2  pgoyette 	(void)feclearexcept(FE_ALL_EXCEPT); \
     46  1.6.2.2  pgoyette } while (/*CONSTCOND*/0)
     47  1.6.2.2  pgoyette 
     48  1.6.2.2  pgoyette # define ATF_CHECK_RAISED_NOTHING do { \
     49  1.6.2.2  pgoyette 	int r = fetestexcept(FE_ALL_EXCEPT); \
     50  1.6.2.2  pgoyette 	ATF_CHECK_MSG(r == 0, "r=%#x != 0\n", r); \
     51  1.6.2.2  pgoyette 	(void)feclearexcept(FE_ALL_EXCEPT); \
     52  1.6.2.2  pgoyette } while (/*CONSTCOND*/0)
     53  1.6.2.2  pgoyette #endif
     54  1.6.2.2  pgoyette 
     55  1.6.2.2  pgoyette ATF_TC(ilogb);
     56  1.6.2.2  pgoyette ATF_TC_HEAD(ilogb, tc)
     57  1.6.2.2  pgoyette {
     58  1.6.2.2  pgoyette 	atf_tc_set_md_var(tc, "descr","Check ilogb family");
     59  1.6.2.2  pgoyette }
     60  1.6.2.2  pgoyette 
     61  1.6.2.2  pgoyette ATF_TC_BODY(ilogb, tc)
     62  1.6.2.2  pgoyette {
     63  1.6.2.2  pgoyette 
     64  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(0) == FP_ILOGB0);
     65  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     66  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(0) == FP_ILOGB0);
     67  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     68  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     69  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(0) == FP_ILOGB0);
     70  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     71  1.6.2.2  pgoyette #endif
     72  1.6.2.2  pgoyette 
     73  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(-0) == FP_ILOGB0);
     74  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     75  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(-0) == FP_ILOGB0);
     76  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     77  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     78  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(-0) == FP_ILOGB0);
     79  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     80  1.6.2.2  pgoyette #endif
     81  1.6.2.2  pgoyette 
     82  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(INFINITY) == INT_MAX);
     83  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     84  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(INFINITY) == INT_MAX);
     85  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     86  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     87  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(INFINITY) == INT_MAX);
     88  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     89  1.6.2.2  pgoyette #endif
     90  1.6.2.2  pgoyette 
     91  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(-INFINITY) == INT_MAX);
     92  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     93  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(-INFINITY) == INT_MAX);
     94  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     95  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
     96  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(-INFINITY) == INT_MAX);
     97  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
     98  1.6.2.2  pgoyette #endif
     99  1.6.2.2  pgoyette 
    100  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(1024) == 10);
    101  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    102  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(1024) == 10);
    103  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    104  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
    105  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(1024) == 10);
    106  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_NOTHING;
    107  1.6.2.2  pgoyette #endif
    108  1.6.2.2  pgoyette 
    109  1.6.2.2  pgoyette #ifndef __vax__
    110  1.6.2.2  pgoyette 	ATF_CHECK(ilogbf(NAN) == FP_ILOGBNAN);
    111  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    112  1.6.2.2  pgoyette 	ATF_CHECK(ilogb(NAN) == FP_ILOGBNAN);
    113  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    114  1.6.2.2  pgoyette #ifdef __HAVE_LONG_DOUBLE
    115  1.6.2.2  pgoyette 	ATF_CHECK(ilogbl(NAN) == FP_ILOGBNAN);
    116  1.6.2.2  pgoyette 	ATF_CHECK_RAISED_INVALID;
    117  1.6.2.2  pgoyette #endif
    118  1.6.2.2  pgoyette #endif
    119  1.6.2.2  pgoyette }
    120  1.6.2.2  pgoyette 
    121  1.6.2.2  pgoyette ATF_TP_ADD_TCS(tp)
    122  1.6.2.2  pgoyette {
    123  1.6.2.2  pgoyette 
    124  1.6.2.2  pgoyette 	ATF_TP_ADD_TC(tp, ilogb);
    125  1.6.2.2  pgoyette 
    126  1.6.2.2  pgoyette 	return atf_no_error();
    127  1.6.2.2  pgoyette }
    128