1 /* $NetBSD: t_floatunditf.c,v 1.5 2014/02/02 08:16:22 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <atf-c.h> 30 #include <atf-c/config.h> 31 #include <inttypes.h> 32 #include <math.h> 33 34 #ifdef __HAVE_LONG_DOUBLE 35 static const struct { 36 uint64_t u64; 37 long double ld; 38 } testcases[] = { 39 { 0xffffffffffffffffULL, 0xf.fffffffffffffffp+60L }, 40 { 0xfffffffffffffffeULL, 0xf.ffffffffffffffep+60L }, 41 { 0xfffffffffffffffdULL, 0xf.ffffffffffffffdp+60L }, 42 { 0xfffffffffffffffcULL, 0xf.ffffffffffffffcp+60L }, 43 { 0x7fffffffffffffffULL, 0xf.ffffffffffffffep+59L }, 44 { 0x3fffffffffffffffULL, 0xf.ffffffffffffffcp+58L }, 45 { 0x1fffffffffffffffULL, 0xf.ffffffffffffff8p+57L }, 46 { 0xfffffffffffffffULL, 0xf.ffffffffffffffp+56L }, 47 { 0x7ffffffffffffffULL, 0xf.fffffffffffffep+55L }, 48 { 0x3ffffffffffffffULL, 0xf.fffffffffffffcp+54L }, 49 { 0x1ffffffffffffffULL, 0xf.fffffffffffff8p+53L }, 50 { 0xffffffffffffffULL, 0xf.fffffffffffffp+52L }, 51 { 0x7fffffffffffffULL, 0xf.ffffffffffffep+51L }, 52 { 0x3fffffffffffffULL, 0xf.ffffffffffffcp+50L }, 53 { 0x1fffffffffffffULL, 0xf.ffffffffffff8p+49L }, 54 { 0xfffffffffffffULL, 0xf.ffffffffffffp+48L }, 55 { 0x7ffffffffffffULL, 0xf.fffffffffffep+47L }, 56 { 0x3ffffffffffffULL, 0xf.fffffffffffcp+46L }, 57 { 0x1ffffffffffffULL, 0xf.fffffffffff8p+45L }, 58 { 0xffffffffffffULL, 0xf.fffffffffffp+44L }, 59 { 0x7fffffffffffULL, 0xf.ffffffffffep+43L }, 60 { 0x3fffffffffffULL, 0xf.ffffffffffcp+42L }, 61 { 0x1fffffffffffULL, 0xf.ffffffffff8p+41L }, 62 { 0xfffffffffffULL, 0xf.ffffffffffp+40L }, 63 { 0x7ffffffffffULL, 0xf.fffffffffep+39L }, 64 { 0x3ffffffffffULL, 0xf.fffffffffcp+38L }, 65 { 0x1ffffffffffULL, 0xf.fffffffff8p+37L }, 66 { 0xffffffffffULL, 0xf.fffffffffp+36L }, 67 { 0x7fffffffffULL, 0xf.ffffffffep+35L }, 68 { 0x3fffffffffULL, 0xf.ffffffffcp+34L }, 69 { 0x1fffffffffULL, 0xf.ffffffff8p+33L }, 70 { 0xfffffffffULL, 0xf.ffffffffp+32L }, 71 { 0x7ffffffffULL, 0xf.fffffffep+31L }, 72 { 0x3ffffffffULL, 0xf.fffffffcp+30L }, 73 { 0x1ffffffffULL, 0xf.fffffff8p+29L }, 74 { 0xffffffffULL, 0xf.fffffffp+28L }, 75 { 0x7fffffffULL, 0xf.ffffffep+27L }, 76 { 0x3fffffffULL, 0xf.ffffffcp+26L }, 77 { 0x1fffffffULL, 0xf.ffffff8p+25L }, 78 { 0xfffffffULL, 0xf.ffffffp+24L }, 79 { 0x7ffffffULL, 0xf.fffffep+23L }, 80 { 0x3ffffffULL, 0xf.fffffcp+22L }, 81 { 0x1ffffffULL, 0xf.fffff8p+21L }, 82 { 0xffffffULL, 0xf.fffffp+20L }, 83 { 0x7fffffULL, 0xf.ffffep+19L }, 84 { 0x3fffffULL, 0xf.ffffcp+18L }, 85 { 0x1fffffULL, 0xf.ffff8p+17L }, 86 { 0xfffffULL, 0xf.ffffp+16L }, 87 { 0x7ffffULL, 0xf.fffep+15L }, 88 { 0x3ffffULL, 0xf.fffcp+14L }, 89 { 0x1ffffULL, 0xf.fff8p+13L }, 90 { 0xffffULL, 0xf.fffp+12L }, 91 { 0x7fffULL, 0xf.ffep+11L }, 92 { 0x3fffULL, 0xf.ffcp+10L }, 93 { 0x1fffULL, 0xf.ff8p+9L }, 94 { 0xfffULL, 0xf.ffp+8L }, 95 { 0x7ffULL, 0xf.fep+7L }, 96 { 0x3ffULL, 0xf.fcp+6L }, 97 { 0x1ffULL, 0xf.f8p+5L }, 98 { 0xffULL, 0xf.fp+4L }, 99 { 0x7fULL, 0xf.ep+3L }, 100 { 0x3fULL, 0xf.cp+2L }, 101 { 0x1fULL, 0xf.8p+1L }, 102 { 0xfULL, 0xfp+0L }, 103 { 0x7ULL, 0xep-1L }, 104 { 0x3ULL, 0xcp-2L }, 105 { 0x1ULL, 0x8p-3L }, 106 }; 107 #endif 108 109 ATF_TC(floatunditf); 110 ATF_TC_HEAD(floatunditf, tc) 111 { 112 atf_tc_set_md_var(tc, "descr", 113 "Verify that uint64 -> long double conversion works"); 114 } 115 116 ATF_TC_BODY(floatunditf, tc) 117 { 118 #ifndef __HAVE_LONG_DOUBLE 119 atf_tc_skip("Requires long double support"); 120 #else 121 size_t i; 122 123 for (i = 0; i < __arraycount(testcases); ++i) 124 ATF_CHECK_MSG( 125 testcases[i].ld == (long double)testcases[i].u64, 126 "#%zu: expected %.20Lf, got %.20Lf\n", i, 127 testcases[i].ld, 128 (long double)testcases[i].u64); 129 #endif 130 } 131 132 ATF_TP_ADD_TCS(tp) 133 { 134 ATF_TP_ADD_TC(tp, floatunditf); 135 return atf_no_error(); 136 } 137