1 /* Test mpz_mul_ui and mpz_mul_si. 2 3 Copyright 2001, 2002 Free Software Foundation, Inc. 4 5 This file is part of the GNU MP Library test suite. 6 7 The GNU MP Library test suite is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 3 of the License, 10 or (at your option) any later version. 11 12 The GNU MP Library test suite is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 Public License for more details. 16 17 You should have received a copy of the GNU General Public License along with 18 the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include "gmp-impl.h" 24 #include "tests.h" 25 26 27 mpz_t got, want, x; 28 29 void 30 compare_si (long y) 31 { 32 if (mpz_cmp (got, want) != 0) 33 { 34 printf ("mpz_mul_si wrong\n"); 35 mpz_trace (" x", x); 36 printf (" y=%ld (0x%lX)\n", y, y); 37 mpz_trace (" got ", got); 38 mpz_trace (" want", want); 39 abort (); 40 } 41 } 42 43 void 44 compare_ui (unsigned long y) 45 { 46 if (mpz_cmp (got, want) != 0) 47 { 48 printf ("mpz_mul_ui wrong\n"); 49 mpz_trace (" x", x); 50 printf (" y=%lu (0x%lX)\n", y, y); 51 mpz_trace (" got ", got); 52 mpz_trace (" want", want); 53 abort (); 54 } 55 } 56 57 void 58 check_samples (void) 59 { 60 { 61 long y; 62 63 mpz_set_ui (x, 1L); 64 y = 0; 65 mpz_mul_si (got, x, y); 66 mpz_set_si (want, y); 67 compare_si (y); 68 69 mpz_set_ui (x, 1L); 70 y = 1; 71 mpz_mul_si (got, x, y); 72 mpz_set_si (want, y); 73 compare_si (y); 74 75 mpz_set_ui (x, 1L); 76 y = -1; 77 mpz_mul_si (got, x, y); 78 mpz_set_si (want, y); 79 compare_si (y); 80 81 mpz_set_ui (x, 1L); 82 y = LONG_MIN; 83 mpz_mul_si (got, x, y); 84 mpz_set_si (want, y); 85 compare_si (y); 86 87 mpz_set_ui (x, 1L); 88 y = LONG_MAX; 89 mpz_mul_si (got, x, y); 90 mpz_set_si (want, y); 91 compare_si (y); 92 } 93 94 { 95 unsigned long y; 96 97 mpz_set_ui (x, 1L); 98 y = 0; 99 mpz_mul_ui (got, x, y); 100 mpz_set_ui (want, y); 101 compare_ui (y); 102 103 mpz_set_ui (x, 1L); 104 y = 1; 105 mpz_mul_ui (got, x, y); 106 mpz_set_ui (want, y); 107 compare_ui (y); 108 109 mpz_set_ui (x, 1L); 110 y = ULONG_MAX; 111 mpz_mul_ui (got, x, y); 112 mpz_set_ui (want, y); 113 compare_ui (y); 114 } 115 } 116 117 int 118 main (int argc, char **argv) 119 { 120 tests_start (); 121 122 mpz_init (x); 123 mpz_init (got); 124 mpz_init (want); 125 126 check_samples (); 127 128 mpz_clear (x); 129 mpz_clear (got); 130 mpz_clear (want); 131 132 tests_end (); 133 exit (0); 134 } 135