Home | History | Annotate | Line # | Download | only in libm
t_ceil.c revision 1.5
      1 /* $NetBSD: t_ceil.c,v 1.5 2011/09/12 16:48:48 jruoho Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jukka Ruohonen.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 #include <sys/cdefs.h>
     32 __RCSID("$NetBSD: t_ceil.c,v 1.5 2011/09/12 16:48:48 jruoho Exp $");
     33 
     34 #include <atf-c.h>
     35 #include <math.h>
     36 #include <limits.h>
     37 #include <stdio.h>
     38 
     39 #ifdef __vax__
     40 #define SMALL_NUM	1.0e-38
     41 #else
     42 #define SMALL_NUM	1.0e-40
     43 #endif
     44 
     45 ATF_TC(ceil_basic);
     46 ATF_TC_HEAD(ceil_basic, tc)
     47 {
     48 	atf_tc_set_md_var(tc, "descr", "A basic test of ceil(3)");
     49 }
     50 
     51 ATF_TC_BODY(ceil_basic, tc)
     52 {
     53 	const double x = 0.999999999999999;
     54 	const double y = 0.000000000000001;
     55 
     56 	ATF_CHECK(fabs(ceil(x) - 1) < SMALL_NUM);
     57 	ATF_CHECK(fabs(ceil(y) - 1) < SMALL_NUM);
     58 }
     59 
     60 ATF_TC(ceilf_basic);
     61 ATF_TC_HEAD(ceilf_basic, tc)
     62 {
     63 	atf_tc_set_md_var(tc, "descr", "A basic test of ceilf(3)");
     64 }
     65 
     66 ATF_TC_BODY(ceilf_basic, tc)
     67 {
     68 	const float x = 0.9999999;
     69 	const float y = 0.0000001;
     70 
     71 	ATF_CHECK(fabsf(ceilf(x) - 1) < SMALL_NUM);
     72 	ATF_CHECK(fabsf(ceilf(y) - 1) < SMALL_NUM);
     73 }
     74 
     75 ATF_TC(floor_basic);
     76 ATF_TC_HEAD(floor_basic, tc)
     77 {
     78 	atf_tc_set_md_var(tc, "descr", "A basic test of floor(3)");
     79 }
     80 
     81 ATF_TC_BODY(floor_basic, tc)
     82 {
     83 	const double x = 0.999999999999999;
     84 	const double y = 0.000000000000001;
     85 
     86 	ATF_CHECK(floor(x) < SMALL_NUM);
     87 	ATF_CHECK(floor(y) < SMALL_NUM);
     88 }
     89 
     90 ATF_TC(floorf_basic);
     91 ATF_TC_HEAD(floorf_basic, tc)
     92 {
     93 	atf_tc_set_md_var(tc, "descr", "A basic test of floorf(3)");
     94 }
     95 
     96 ATF_TC_BODY(floorf_basic, tc)
     97 {
     98 	const float x = 0.9999999;
     99 	const float y = 0.0000001;
    100 
    101 	ATF_CHECK(floorf(x) < SMALL_NUM);
    102 	ATF_CHECK(floorf(y) < SMALL_NUM);
    103 }
    104 
    105 ATF_TP_ADD_TCS(tp)
    106 {
    107 
    108 	ATF_TP_ADD_TC(tp, ceil_basic);
    109 	ATF_TP_ADD_TC(tp, ceilf_basic);
    110 	ATF_TP_ADD_TC(tp, floorf_basic);
    111 	ATF_TP_ADD_TC(tp, floorf_basic);
    112 
    113 	return atf_no_error();
    114 }
    115