blob: f8898eef9d45edd329f795dc23b705a92cb40a39 [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/* Test mp*_class operators and functions.
2
3Copyright 2011, 2012 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
19
20#include "config.h"
21
22#include <math.h>
23
24#include "gmpxx.h"
25#include "gmp-impl.h"
26#include "tests.h"
27
28
29#define CHECK1(Type,a,fun) \
30 ASSERT_ALWAYS(fun((Type)(a))==fun(a))
31#define CHECK(Type1,Type2,a,b,op) \
32 ASSERT_ALWAYS(((Type1)(a) op (Type2)(b))==((a) op (b)))
33#define CHECK_G(Type,a,b,op) \
34 CHECK(Type,Type,a,b,op)
35#define CHECK_UI(Type,a,b,op) \
36 CHECK(Type,unsigned long,a,b,op); \
37 CHECK(unsigned long,Type,a,b,op)
38#define CHECK_SI(Type,a,b,op) \
39 CHECK(Type,long,a,b,op); \
40 CHECK(long,Type,a,b,op)
41#define CHECK_D(Type,a,b,op) \
42 CHECK(Type,double,a,b,op); \
43 CHECK(double,Type,a,b,op)
44#define CHECK_MPZ(Type,a,b,op) \
45 CHECK(Type,mpz_class,a,b,op); \
46 CHECK(mpz_class,Type,a,b,op)
47#define CHECK_MPQ(Type,a,b,op) \
48 CHECK(Type,mpq_class,a,b,op); \
49 CHECK(mpq_class,Type,a,b,op)
50#define CHECK_ALL_SIGNED(Type,a,b,op) \
51 CHECK_G(Type,a,b,op); \
52 CHECK_SI(Type,a,b,op); \
53 CHECK_D(Type,a,b,op)
54#define CHECK_ALL_SIGNS(Type,a,b,op) \
55 CHECK_ALL_SIGNED(Type,a,b,op); \
56 CHECK_ALL_SIGNED(Type,-(a),b,op); \
57 CHECK_ALL_SIGNED(Type,a,-(b),op); \
58 CHECK_ALL_SIGNED(Type,-(a),-(b),op)
59#define CHECK_ALL(Type,a,b,op) \
60 CHECK_ALL_SIGNED(Type,a,b,op); \
61 CHECK_UI(Type,a,b,op)
62#define CHECK_ALL_SIGNED_COMPARISONS(Type,a,b) \
63 CHECK_ALL_SIGNED(Type,a,b,<); \
64 CHECK_ALL_SIGNED(Type,a,b,>); \
65 CHECK_ALL_SIGNED(Type,a,b,<=); \
66 CHECK_ALL_SIGNED(Type,a,b,>=); \
67 CHECK_ALL_SIGNED(Type,a,b,==); \
68 CHECK_ALL_SIGNED(Type,a,b,!=)
69#define CHECK_ALL_SIGNS_COMPARISONS(Type,a,b) \
70 CHECK_ALL_SIGNS(Type,a,b,<); \
71 CHECK_ALL_SIGNS(Type,a,b,>); \
72 CHECK_ALL_SIGNS(Type,a,b,<=); \
73 CHECK_ALL_SIGNS(Type,a,b,>=); \
74 CHECK_ALL_SIGNS(Type,a,b,==); \
75 CHECK_ALL_SIGNS(Type,a,b,!=)
76#define CHECK_ALL_COMPARISONS(Type,a,b) \
77 CHECK_ALL(Type,a,b,<); \
78 CHECK_ALL(Type,a,b,>); \
79 CHECK_ALL(Type,a,b,<=); \
80 CHECK_ALL(Type,a,b,>=); \
81 CHECK_ALL(Type,a,b,==); \
82 CHECK_ALL(Type,a,b,!=)