3 Copyright 2001 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
29 check_one (mpq_srcptr q, int base, const char *want)
38 mpz_sizeinbase (mpq_numref(q), ABS(base)) +
39 mpz_sizeinbase (mpq_denref(q), ABS(base)) + 3;
41 str = mpq_get_str (NULL, base, q);
42 if (strlen(str)+1 > str_alloc)
44 printf ("mpq_get_str size bigger than should be (passing NULL)\n");
45 printf (" base %d\n", base);
46 printf (" got size %lu \"%s\"\n", (unsigned long) strlen(str)+1, str);
47 printf (" want size %lu\n", (unsigned long) str_alloc);
50 if (strcmp (str, want) != 0)
52 printf ("mpq_get_str wrong (passing NULL)\n");
53 printf (" base %d\n", base);
54 printf (" got \"%s\"\n", str);
55 printf (" want \"%s\"\n", want);
59 (*__gmp_free_func) (str, strlen (str) + 1);
61 str = (char *) (*__gmp_allocate_func) (str_alloc);
63 ret = mpq_get_str (str, base, q);
66 printf ("mpq_get_str wrong return value (passing non-NULL)\n");
67 printf (" base %d\n", base);
68 printf (" got %p\n", ret);
69 printf (" want %p\n", want);
72 if (strcmp (str, want) != 0)
74 printf ("mpq_get_str wrong (passing non-NULL)\n");
75 printf (" base %d\n", base);
76 printf (" got \"%s\"\n", str);
77 printf (" want \"%s\"\n", want);
80 (*__gmp_free_func) (str, str_alloc);
85 check_all (mpq_srcptr q, int base, const char *want)
89 check_one (q, base, want);
91 s = __gmp_allocate_strdup (want);
93 check_one (q, -base, s);
94 (*__gmp_free_func) (s, strlen(s)+1);
100 static const struct {
106 { 10, "0", "1", "0" },
107 { 10, "1", "1", "1" },
109 { 16, "ffffffff", "1", "ffffffff" },
110 { 16, "ffffffffffffffff", "1", "ffffffffffffffff" },
112 { 16, "1", "ffffffff", "1/ffffffff" },
113 { 16, "1", "ffffffffffffffff", "1/ffffffffffffffff" },
114 { 16, "1", "10000000000000003", "1/10000000000000003" },
116 { 10, "12345678901234567890", "9876543210987654323",
117 "12345678901234567890/9876543210987654323" },
124 for (i = 0; i < numberof (data); i++)
126 mpz_set_str_or_abort (mpq_numref(q), data[i].num, data[i].base);
127 mpz_set_str_or_abort (mpq_denref(q), data[i].den, data[i].base);
128 check_all (q, data[i].base, data[i].want);