1 /* $NetBSD: t_remquo.c,v 1.2 2024/09/20 22:24:51 rin 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 and Greg Troxel. 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 32 #include <assert.h> 33 #include <atf-c.h> 34 #include <float.h> 35 #include <math.h> 36 37 /* 38 * remquo(3) 39 */ 40 ATF_TC(remquo_args); 41 ATF_TC_HEAD(remquo_args, tc) 42 { 43 atf_tc_set_md_var(tc, "descr", "Test some selected arguments"); 44 } 45 46 ATF_TP_ADD_TCS(tp) 47 { 48 49 ATF_TP_ADD_TC(tp, remquo_args); 50 51 return atf_no_error(); 52 } 53 54 #ifdef __vax__ 55 56 ATF_TC_BODY(remquo_args, tc) 57 { 58 atf_tc_expect_fail("PR 57881: vax libm is missing various symbols"); 59 atf_tc_fail("missing remquo on vax"); 60 } 61 62 #else /* !__vax__ */ 63 64 static const struct { 65 double x; 66 double y; 67 double r; /* expected */ 68 int quo; /* expected */ 69 } args[] = { 70 { -135.0, -90.0, 45.0, 2 }, 71 { -45.0, -90.0, -45.0, 8 }, 72 { 45.0, -90.0, 45.0, -8 }, 73 { 135.0, -90.0, -45.0, -2 }, 74 { -180.0, 90.0, -0.0, -2 }, 75 { -135.0, 90.0, 45.0, -2 }, 76 { -90.0, 90.0, -0.0, -1 }, 77 { -45.0, 90.0, -45.0, -8 }, 78 { 0.0, 90.0, 0.0, 0 }, 79 { 45.0, 90.0, 45.0, 8 }, 80 { 90.0, 90.0, 0.0, 1 }, 81 { 135.0, 90.0, -45.0, 2 }, 82 { 180.0, 90.0, 0.0, 2 }, 83 }; 84 85 ATF_TC_BODY(remquo_args, tc) 86 { 87 const double eps = DBL_EPSILON; 88 size_t i; 89 90 for (i = 0; i < __arraycount(args); i++) { 91 double x = args[i].x; 92 double y = args[i].y; 93 double r; 94 double r_exp = args[i].r; 95 int quo; 96 int quo_exp = args[i].quo; 97 98 bool ok = true; 99 100 r = remquo(x, y, &quo); 101 102 ok &= (fabs(r - r_exp) <= eps); 103 104 /* 105 * For now, consider 0 to have positive sign. 106 */ 107 if (quo_exp < 0 && quo >= 0) 108 ok = false; 109 if (quo_exp >= 0 && quo < 0) 110 ok = false; 111 112 /* 113 * The specification requires that quo be congruent to 114 * the integer remainder modulo 2^k for some k >=3. 115 */ 116 ok &= ((quo & 0x7) == (quo_exp & 0x7)); 117 118 if (!ok) { 119 atf_tc_fail_nonfatal("remquo(%g, %g) " 120 "r/quo expected %g/%d != %g/%d", 121 x, y, r_exp, quo_exp, r, quo); 122 } 123 } 124 } 125 126 #endif /* !__vax__ */ 127