t_infinity.c revision 272343
1272343Sngie/* $NetBSD: t_infinity.c,v 1.6 2012/09/26 07:24:38 jruoho Exp $ */ 2272343Sngie 3272343Sngie/*- 4272343Sngie * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * This code is derived from software contributed to The NetBSD Foundation 8272343Sngie * by Martin Husemann <martin@NetBSD.org>. 9272343Sngie * 10272343Sngie * Redistribution and use in source and binary forms, with or without 11272343Sngie * modification, are permitted provided that the following conditions 12272343Sngie * are met: 13272343Sngie * 1. Redistributions of source code must retain the above copyright 14272343Sngie * notice, this list of conditions and the following disclaimer. 15272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 16272343Sngie * notice, this list of conditions and the following disclaimer in the 17272343Sngie * documentation and/or other materials provided with the distribution. 18272343Sngie * 19272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20272343Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21272343Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22272343Sngie * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23272343Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24272343Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25272343Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27272343Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28272343Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29272343Sngie * POSSIBILITY OF SUCH DAMAGE. 30272343Sngie */ 31272343Sngie#include <sys/cdefs.h> 32272343Sngie__RCSID("$NetBSD: t_infinity.c,v 1.6 2012/09/26 07:24:38 jruoho Exp $"); 33272343Sngie 34272343Sngie#include <atf-c.h> 35272343Sngie#include <math.h> 36272343Sngie#include <float.h> 37272343Sngie#include <stdlib.h> 38272343Sngie 39272343SngieATF_TC(infinity_float); 40272343SngieATF_TC_HEAD(infinity_float, tc) 41272343Sngie{ 42272343Sngie atf_tc_set_md_var(tc, "descr", 43272343Sngie "check FPU generated infinite float values"); 44272343Sngie} 45272343Sngie 46272343SngieATF_TC_BODY(infinity_float, tc) 47272343Sngie{ 48272343Sngie float v; 49272343Sngie 50272343Sngie v = FLT_MAX; 51272343Sngie v *= v; 52272343Sngie ATF_REQUIRE(isinf(v)); 53272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 54272343Sngie 55272343Sngie v = -FLT_MAX; 56272343Sngie v *= v; 57272343Sngie ATF_REQUIRE(isinf(v)); 58272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 59272343Sngie} 60272343Sngie 61272343SngieATF_TC(infinity_double); 62272343SngieATF_TC_HEAD(infinity_double, tc) 63272343Sngie{ 64272343Sngie atf_tc_set_md_var(tc, "descr", 65272343Sngie "check FPU generated infinite double values"); 66272343Sngie} 67272343Sngie 68272343SngieATF_TC_BODY(infinity_double, tc) 69272343Sngie{ 70272343Sngie double v; 71272343Sngie 72272343Sngie v = DBL_MAX; 73272343Sngie v *= v; 74272343Sngie ATF_REQUIRE(isinf(v)); 75272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 76272343Sngie 77272343Sngie v = -DBL_MAX; 78272343Sngie v *= v; 79272343Sngie ATF_REQUIRE(isinf(v)); 80272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 81272343Sngie} 82272343Sngie 83272343SngieATF_TC(infinity_long_double); 84272343SngieATF_TC_HEAD(infinity_long_double, tc) 85272343Sngie{ 86272343Sngie atf_tc_set_md_var(tc, "descr", 87272343Sngie "check FPU generated infinite long double values"); 88272343Sngie} 89272343Sngie 90272343SngieATF_TC_BODY(infinity_long_double, tc) 91272343Sngie{ 92272343Sngie 93272343Sngie#ifndef LDBL_MAX 94272343Sngie atf_tc_skip("no long double support on this architecture"); 95272343Sngie return; 96272343Sngie#else 97272343Sngie long double v; 98272343Sngie 99272343Sngie v = LDBL_MAX; 100272343Sngie v *= v; 101272343Sngie ATF_REQUIRE(isinf(v)); 102272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 103272343Sngie 104272343Sngie v = -LDBL_MAX; 105272343Sngie v *= v; 106272343Sngie ATF_REQUIRE(isinf(v)); 107272343Sngie ATF_REQUIRE(fpclassify(v) == FP_INFINITE); 108272343Sngie#endif 109272343Sngie} 110272343Sngie 111272343SngieATF_TP_ADD_TCS(tp) 112272343Sngie{ 113272343Sngie 114272343Sngie ATF_TP_ADD_TC(tp, infinity_float); 115272343Sngie ATF_TP_ADD_TC(tp, infinity_double); 116272343Sngie ATF_TP_ADD_TC(tp, infinity_long_double); 117272343Sngie 118272343Sngie return atf_no_error(); 119272343Sngie} 120