1 /* tdot -- test file for mpfr_dot 2 3 Copyright 2018-2023 Free Software Foundation, Inc. 4 Contributed by the AriC and Caramba projects, INRIA. 5 6 This file is part of the GNU MPFR Library. 7 8 The GNU MPFR Library is free software; you can redistribute it and/or modify 9 it under the terms of the GNU Lesser General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 13 The GNU MPFR Library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 20 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 #include "mpfr-test.h" 24 25 static void 26 check_simple (void) 27 { 28 mpfr_t tab[3], r; 29 mpfr_ptr tabp[3]; 30 int i; 31 32 mpfr_init2 (r, 16); 33 for (i = 0; i < 3; i++) 34 { 35 mpfr_init2 (tab[i], 16); 36 mpfr_set_ui (tab[i], 1, MPFR_RNDN); 37 tabp[i] = tab[i]; 38 } 39 40 i = mpfr_dot (r, tabp, tabp, 3, MPFR_RNDN); 41 if (mpfr_cmp_ui0 (r, 3) || i != 0) 42 { 43 printf ("Error in check_simple\n"); 44 exit (1); 45 } 46 47 mpfr_clears (tab[0], tab[1], tab[2], r, (mpfr_ptr) 0); 48 } 49 50 static void 51 check_special (void) 52 { 53 mpfr_t tab[3], r; 54 mpfr_ptr tabp[3]; 55 int i; 56 int rnd; 57 58 mpfr_inits2 (53, tab[0], tab[1], tab[2], r, (mpfr_ptr) 0); 59 tabp[0] = tab[0]; 60 tabp[1] = tab[1]; 61 tabp[2] = tab[2]; 62 63 RND_LOOP (rnd) 64 { 65 i = mpfr_dot (r, tabp, tabp, 0, (mpfr_rnd_t) rnd); 66 if (!MPFR_IS_ZERO (r) || !MPFR_IS_POS (r) || i != 0) 67 { 68 printf ("Special case n==0 failed for %s!\n", 69 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 70 exit (1); 71 } 72 } 73 74 mpfr_set_ui (tab[0], 42, MPFR_RNDN); 75 RND_LOOP (rnd) 76 { 77 i = mpfr_dot (r, tabp, tabp, 1, (mpfr_rnd_t) rnd); 78 if (mpfr_cmp_ui0 (r, 42*42) || i != 0) 79 { 80 printf ("Special case n==1 failed for %s!\n", 81 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 82 exit (1); 83 } 84 } 85 86 mpfr_set_ui (tab[1], 17, MPFR_RNDN); 87 MPFR_SET_NAN (tab[2]); 88 RND_LOOP (rnd) 89 { 90 i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd); 91 if (!MPFR_IS_NAN (r) || i != 0) 92 { 93 printf ("Special case NAN failed for %s!\n", 94 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 95 exit (1); 96 } 97 } 98 99 MPFR_SET_INF (tab[2]); 100 MPFR_SET_POS (tab[2]); 101 RND_LOOP (rnd) 102 { 103 i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd); 104 if (!MPFR_IS_INF (r) || !MPFR_IS_POS (r) || i != 0) 105 { 106 printf ("Special case +INF failed for %s!\n", 107 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 108 exit (1); 109 } 110 } 111 112 MPFR_SET_INF (tab[2]); 113 MPFR_SET_NEG (tab[2]); 114 RND_LOOP (rnd) 115 { 116 i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd); 117 if (!MPFR_IS_INF (r) || !MPFR_IS_POS (r) || i != 0) 118 { 119 printf ("Special case +INF failed for %s!\n", 120 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 121 exit (1); 122 } 123 } 124 125 MPFR_SET_ZERO (tab[1]); 126 RND_LOOP (rnd) 127 { 128 i = mpfr_dot (r, tabp, tabp, 2, (mpfr_rnd_t) rnd); 129 if (mpfr_cmp_ui0 (r, 42*42) || i != 0) 130 { 131 printf ("Special case 42+0 failed for %s!\n", 132 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 133 exit (1); 134 } 135 } 136 137 MPFR_SET_NAN (tab[0]); 138 RND_LOOP (rnd) 139 { 140 i = mpfr_dot (r, tabp, tabp, 3, (mpfr_rnd_t) rnd); 141 if (!MPFR_IS_NAN (r) || i != 0) 142 { 143 printf ("Special case NAN+0+-INF failed for %s!\n", 144 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 145 exit (1); 146 } 147 } 148 149 mpfr_set_inf (tab[0], 1); 150 mpfr_set_inf (tab[0], 1); 151 mpfr_set_inf (tab[2], -1); 152 RND_LOOP (rnd) 153 { 154 i = mpfr_dot (r, tabp, tabp + 1, 2, (mpfr_rnd_t) rnd); 155 if (!MPFR_IS_NAN (r) || i != 0) 156 { 157 printf ("Special case inf*inf-inf*inf failed for %s!\n", 158 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); 159 exit (1); 160 } 161 } 162 163 mpfr_clears (tab[0], tab[1], tab[2], r, (mpfr_ptr) 0); 164 } 165 166 int 167 main (int argc, char *argv[]) 168 { 169 tests_start_mpfr (); 170 171 check_simple (); 172 check_special (); 173 174 tests_end_mpfr (); 175 176 return 0; 177 } 178