1 /* Test of libgmp or its mini-mpq substitute.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
30 /* A simple sanity check that 2/3 + 2/3 = 4/3. */
31 static mp_limb_t
const twobody
[] = { 2 };
32 static mp_limb_t
const threebody
[] = { 3 };
33 static mpz_t
const two
= MPZ_ROINIT_N ((mp_limb_t
*) twobody
, 1);
34 static mpz_t
const three
= MPZ_ROINIT_N ((mp_limb_t
*) threebody
, 1);
35 ASSERT (mpz_fits_slong_p (two
));
36 ASSERT (mpz_get_si (two
) == 2);
37 ASSERT (mpz_fits_slong_p (three
));
38 ASSERT (mpz_get_si (three
) == 3);
42 mpz_set (mpq_numref (q
), two
);
43 mpz_set (mpq_denref (q
), three
);
45 ASSERT (mpz_fits_slong_p (mpq_numref (q
)));
46 ASSERT (mpz_get_si (mpq_numref (q
)) == 4);
47 ASSERT (mpz_fits_slong_p (mpq_denref (q
)));
48 ASSERT (mpz_get_si (mpq_denref (q
)) == 3);
51 return test_exit_status
;