1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2014, 2020 William Hart
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "test_helpers.h"
#include "ulong_extras.h"
#include "fmpq.h"
TEST_FUNCTION_START(fmpq_sub_ui, state)
{
int i;
/* x = y + z */
for (i = 0; i < 10000; i++)
{
fmpq_t x, y;
ulong z;
fmpq_t X, Y, Z;
fmpq_init(x);
fmpq_init(y);
fmpq_init(X);
fmpq_init(Y);
fmpq_init(Z);
fmpq_randtest(x, state, 200);
fmpq_randtest(y, state, 200);
z = n_randtest(state);
fmpq_set(X, x);
fmpq_set(Y, y);
fmpq_set_ui(Z, z, 1);
fmpq_sub_ui(x, y, z);
if (!fmpq_is_canonical(x))
{
flint_printf("FAIL: result not canonical!\n");
fflush(stdout);
flint_abort();
}
fmpq_sub(X, Y, Z);
if (!fmpq_equal(X, x))
{
flint_printf("FAIL: fmpq_add(x,y,z) != mpq_add(X,Y,Z)\n");
flint_printf("x = ");
fmpq_print(x);
flint_printf("\ny = ");
fmpq_print(y);
flint_printf("\nz = ");
flint_printf("%wd", z);
flint_printf("\n");
fflush(stdout);
flint_abort();
}
fmpq_clear(x);
fmpq_clear(y);
fmpq_clear(X);
fmpq_clear(Y);
fmpq_clear(Z);
}
/* x = x + y */
for (i = 0; i < 10000; i++)
{
fmpq_t x;
ulong y;
fmpq_t X, Y;
fmpq_init(x);
fmpq_init(X);
fmpq_init(Y);
fmpq_randtest(x, state, 200);
y = n_randtest(state);
fmpq_set(X, x);
fmpq_set_ui(Y, y, 1);
fmpq_sub_ui(x, x, y);
fmpq_sub(X, X, Y);
if (!fmpq_is_canonical(x))
{
flint_printf("FAIL: result not canonical!\n");
fflush(stdout);
flint_abort();
}
if (!fmpq_equal(X, x))
{
flint_printf("FAIL: fmpq_add(x,x,y) != mpq_add(X,X,Y)\n");
flint_printf("x = ");
fmpq_print(x);
flint_printf("\ny = ");
flint_printf("%wd", y);
flint_printf("\n");
fflush(stdout);
flint_abort();
}
fmpq_clear(x);
fmpq_clear(X);
fmpq_clear(Y);
}
TEST_FUNCTION_END(state);
}