xref: /netbsd-src/external/lgpl3/gmp/dist/tests/cxx/t-ops2f.cc (revision 72c7faa4dbb41dbb0238d6b4a109da0d4b236dd4)
1 /* Test mp*_class operators and functions.
2 
3 Copyright 2011, 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 "t-ops2.h"
21 
checkf()22 void checkf (){
23   ASSERT_ALWAYS(sqrt(mpf_class(7))>2.64);
24   ASSERT_ALWAYS(sqrt(mpf_class(7))<2.65);
25   ASSERT_ALWAYS(sqrt(mpf_class(0))==0);
26   // TODO: add some consistency checks, as described in
27   // https://gmplib.org/list-archives/gmp-bugs/2013-February/002940.html
28   CHECK1(mpf_class,1.9,trunc);
29   CHECK1(mpf_class,1.9,floor);
30   CHECK1(mpf_class,1.9,ceil);
31   CHECK1(mpf_class,4.3,trunc);
32   CHECK1(mpf_class,4.3,floor);
33   CHECK1(mpf_class,4.3,ceil);
34   CHECK1(mpf_class,-7.1,trunc);
35   CHECK1(mpf_class,-7.1,floor);
36   CHECK1(mpf_class,-7.1,ceil);
37   CHECK1(mpf_class,-2.8,trunc);
38   CHECK1(mpf_class,-2.8,floor);
39   CHECK1(mpf_class,-2.8,ceil);
40   CHECK1(mpf_class,-1.5,trunc);
41   CHECK1(mpf_class,-1.5,floor);
42   CHECK1(mpf_class,-1.5,ceil);
43   CHECK1(mpf_class,2.5,trunc);
44   CHECK1(mpf_class,2.5,floor);
45   CHECK1(mpf_class,2.5,ceil);
46   ASSERT_ALWAYS(hypot(mpf_class(-3),mpf_class(4))>4.9);
47   ASSERT_ALWAYS(hypot(mpf_class(-3),mpf_class(4))<5.1);
48   ASSERT_ALWAYS(hypot(mpf_class(-3),4.)>4.9);
49   ASSERT_ALWAYS(hypot(-3.,mpf_class(4))<5.1);
50   ASSERT_ALWAYS(hypot(mpf_class(-3),4l)>4.9);
51   ASSERT_ALWAYS(hypot(-3l,mpf_class(4))<5.1);
52   ASSERT_ALWAYS(hypot(mpf_class(-3),4ul)>4.9);
53   ASSERT_ALWAYS(hypot(3ul,mpf_class(4))<5.1);
54   CHECK(mpf_class,mpq_class,1.5,2.25,+);
55   CHECK(mpf_class,mpq_class,1.5,2.25,-);
56   CHECK(mpf_class,mpq_class,1.5,-2.25,*);
57   CHECK(mpf_class,mpq_class,1.5,-2,/);
58   CHECK_MPQ(mpf_class,-5.5,-2.25,+);
59   CHECK_MPQ(mpf_class,-5.5,-2.25,-);
60   CHECK_MPQ(mpf_class,-5.5,-2.25,*);
61   CHECK_MPQ(mpf_class,-5.25,-0.5,/);
62   CHECK_MPQ(mpf_class,5,-2,<);
63   CHECK_MPQ(mpf_class,5,-2,>);
64   CHECK_MPQ(mpf_class,5,-2,<=);
65   CHECK_MPQ(mpf_class,5,-2,>=);
66   CHECK_MPQ(mpf_class,5,-2,==);
67   CHECK_MPQ(mpf_class,5,-2,!=);
68   CHECK_MPQ(mpf_class,0,0,<);
69   CHECK_MPQ(mpf_class,0,0,>);
70   CHECK_MPQ(mpf_class,0,0,<=);
71   CHECK_MPQ(mpf_class,0,0,>=);
72   CHECK_MPQ(mpf_class,0,0,==);
73   CHECK_MPQ(mpf_class,0,0,!=);
74 }
75 
76 int
main(void)77 main (void)
78 {
79   tests_start();
80 
81   // Enough precision for 1 + denorm_min
82   mpf_set_default_prec(DBL_MANT_DIG-DBL_MIN_EXP+42);
83   checkf();
84 
85   tests_end();
86   return 0;
87 }
88