Austin Schuh | dace2a6 | 2020-08-18 10:56:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Copyright 2012, 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 <limits.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #include "testutils.h" |
| 25 | |
| 26 | #define MAXBITS 400 |
| 27 | #define COUNT 10000 |
| 28 | |
| 29 | void |
| 30 | testmain (int argc, char **argv) |
| 31 | { |
| 32 | unsigned i; |
| 33 | mpz_t a, b, g, s; |
| 34 | |
| 35 | mpz_init (a); |
| 36 | mpz_init (b); |
| 37 | mpz_init (g); |
| 38 | mpz_init (s); |
| 39 | |
| 40 | for (i = 0; i < COUNT; i++) |
| 41 | { |
| 42 | mini_random_op3 (OP_LCM, MAXBITS, a, b, s); |
| 43 | mpz_lcm (g, a, b); |
| 44 | if (mpz_cmp (g, s)) |
| 45 | { |
| 46 | fprintf (stderr, "mpz_lcm failed:\n"); |
| 47 | dump ("a", a); |
| 48 | dump ("b", b); |
| 49 | dump ("r", g); |
| 50 | dump ("ref", s); |
| 51 | abort (); |
| 52 | } |
| 53 | if (mpz_fits_ulong_p (b)) |
| 54 | { |
| 55 | mpz_set_si (g, 0); |
| 56 | mpz_lcm_ui (g, a, mpz_get_ui (b)); |
| 57 | if (mpz_cmp (g, s)) |
| 58 | { |
| 59 | fprintf (stderr, "mpz_lcm_ui failed:\n"); |
| 60 | dump ("a", a); |
| 61 | dump ("b", b); |
| 62 | dump ("r", g); |
| 63 | dump ("ref", s); |
| 64 | abort (); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | mpz_clear (a); |
| 70 | mpz_clear (b); |
| 71 | mpz_clear (g); |
| 72 | mpz_clear (s); |
| 73 | } |