1 1.2 rin /* $NetBSD: t_remquo.c,v 1.2 2024/09/20 22:24:51 rin Exp $ */ 2 1.1 gdt 3 1.1 gdt /*- 4 1.1 gdt * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 1.1 gdt * All rights reserved. 6 1.1 gdt * 7 1.1 gdt * This code is derived from software contributed to The NetBSD Foundation 8 1.1 gdt * by Jukka Ruohonen and Greg Troxel. 9 1.1 gdt * 10 1.1 gdt * Redistribution and use in source and binary forms, with or without 11 1.1 gdt * modification, are permitted provided that the following conditions 12 1.1 gdt * are met: 13 1.1 gdt * 1. Redistributions of source code must retain the above copyright 14 1.1 gdt * notice, this list of conditions and the following disclaimer. 15 1.1 gdt * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 gdt * notice, this list of conditions and the following disclaimer in the 17 1.1 gdt * documentation and/or other materials provided with the distribution. 18 1.1 gdt * 19 1.1 gdt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 gdt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 gdt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 gdt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 gdt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 gdt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 gdt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 gdt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 gdt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 gdt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 gdt * POSSIBILITY OF SUCH DAMAGE. 30 1.1 gdt */ 31 1.1 gdt 32 1.1 gdt #include <assert.h> 33 1.1 gdt #include <atf-c.h> 34 1.1 gdt #include <float.h> 35 1.1 gdt #include <math.h> 36 1.1 gdt 37 1.2 rin /* 38 1.2 rin * remquo(3) 39 1.2 rin */ 40 1.2 rin ATF_TC(remquo_args); 41 1.2 rin ATF_TC_HEAD(remquo_args, tc) 42 1.2 rin { 43 1.2 rin atf_tc_set_md_var(tc, "descr", "Test some selected arguments"); 44 1.2 rin } 45 1.2 rin 46 1.2 rin ATF_TP_ADD_TCS(tp) 47 1.2 rin { 48 1.2 rin 49 1.2 rin ATF_TP_ADD_TC(tp, remquo_args); 50 1.2 rin 51 1.2 rin return atf_no_error(); 52 1.2 rin } 53 1.2 rin 54 1.2 rin #ifdef __vax__ 55 1.2 rin 56 1.2 rin ATF_TC_BODY(remquo_args, tc) 57 1.2 rin { 58 1.2 rin atf_tc_expect_fail("PR 57881: vax libm is missing various symbols"); 59 1.2 rin atf_tc_fail("missing remquo on vax"); 60 1.2 rin } 61 1.2 rin 62 1.2 rin #else /* !__vax__ */ 63 1.2 rin 64 1.1 gdt static const struct { 65 1.1 gdt double x; 66 1.1 gdt double y; 67 1.1 gdt double r; /* expected */ 68 1.1 gdt int quo; /* expected */ 69 1.1 gdt } args[] = { 70 1.1 gdt { -135.0, -90.0, 45.0, 2 }, 71 1.1 gdt { -45.0, -90.0, -45.0, 8 }, 72 1.1 gdt { 45.0, -90.0, 45.0, -8 }, 73 1.1 gdt { 135.0, -90.0, -45.0, -2 }, 74 1.1 gdt { -180.0, 90.0, -0.0, -2 }, 75 1.1 gdt { -135.0, 90.0, 45.0, -2 }, 76 1.1 gdt { -90.0, 90.0, -0.0, -1 }, 77 1.1 gdt { -45.0, 90.0, -45.0, -8 }, 78 1.1 gdt { 0.0, 90.0, 0.0, 0 }, 79 1.1 gdt { 45.0, 90.0, 45.0, 8 }, 80 1.1 gdt { 90.0, 90.0, 0.0, 1 }, 81 1.1 gdt { 135.0, 90.0, -45.0, 2 }, 82 1.1 gdt { 180.0, 90.0, 0.0, 2 }, 83 1.1 gdt }; 84 1.1 gdt 85 1.1 gdt ATF_TC_BODY(remquo_args, tc) 86 1.1 gdt { 87 1.1 gdt const double eps = DBL_EPSILON; 88 1.1 gdt size_t i; 89 1.1 gdt 90 1.1 gdt for (i = 0; i < __arraycount(args); i++) { 91 1.1 gdt double x = args[i].x; 92 1.1 gdt double y = args[i].y; 93 1.1 gdt double r; 94 1.1 gdt double r_exp = args[i].r; 95 1.1 gdt int quo; 96 1.1 gdt int quo_exp = args[i].quo; 97 1.1 gdt 98 1.1 gdt bool ok = true; 99 1.1 gdt 100 1.1 gdt r = remquo(x, y, &quo); 101 1.1 gdt 102 1.1 gdt ok &= (fabs(r - r_exp) <= eps); 103 1.1 gdt 104 1.1 gdt /* 105 1.1 gdt * For now, consider 0 to have positive sign. 106 1.1 gdt */ 107 1.1 gdt if (quo_exp < 0 && quo >= 0) 108 1.1 gdt ok = false; 109 1.1 gdt if (quo_exp >= 0 && quo < 0) 110 1.1 gdt ok = false; 111 1.1 gdt 112 1.1 gdt /* 113 1.1 gdt * The specification requires that quo be congruent to 114 1.1 gdt * the integer remainder modulo 2^k for some k >=3. 115 1.1 gdt */ 116 1.1 gdt ok &= ((quo & 0x7) == (quo_exp & 0x7)); 117 1.1 gdt 118 1.1 gdt if (!ok) { 119 1.1 gdt atf_tc_fail_nonfatal("remquo(%g, %g) " 120 1.1 gdt "r/quo expected %g/%d != %g/%d", 121 1.1 gdt x, y, r_exp, quo_exp, r, quo); 122 1.1 gdt } 123 1.1 gdt } 124 1.1 gdt } 125 1.1 gdt 126 1.2 rin #endif /* !__vax__ */ 127