1/* Test mp*_class operators and functions. 2 3Copyright 2011, 2012, 2018 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 "t-ops2.h" 21 22template<class T> 23void checkqf (){ 24 CHECK_ALL(T,5.,0,+); 25 CHECK_ALL(T,5.,0,-); 26 CHECK_ALL(T,5.,2,+); CHECK_MPZ(T,5.,2,+); 27 CHECK_ALL(T,5.,2,-); CHECK_MPZ(T,5.,2,-); 28 CHECK_ALL(T,5.,2,*); CHECK_MPZ(T,5.,2,*); 29 CHECK_ALL(T,5.,2,/); CHECK_MPZ(T,5.,2,/); 30 CHECK_ALL(T,0.,2,/); 31 CHECK_ALL_SIGNS(T,11.,3,+); 32 CHECK_ALL_SIGNS(T,11.,3,-); 33 CHECK_ALL_SIGNS(T,13.,1,+); 34 CHECK_ALL_SIGNS(T,13.,1,-); 35 CHECK_ALL_SIGNS(T,11.,3,*); 36 CHECK_ALL_SIGNS(T,11.,4,/); 37 CHECK_SI(T,LONG_MIN,1,*); 38 CHECK_SI(T,0,3,*); 39 CHECK_ALL_COMPARISONS(T,5.,2); 40 CHECK_ALL_SIGNS_COMPARISONS(T,11.,3); 41 CHECK_MPZ(T,5,-2,<); 42 CHECK_MPZ(T,5,-2,>); 43 CHECK_MPZ(T,5,-2,<=); 44 CHECK_MPZ(T,5,-2,>=); 45 CHECK_MPZ(T,5,-2,==); 46 CHECK_MPZ(T,5,-2,!=); 47 CHECK_MPZ(T,0,0,<); 48 CHECK_MPZ(T,0,0,>); 49 CHECK_MPZ(T,0,0,<=); 50 CHECK_MPZ(T,0,0,>=); 51 CHECK_MPZ(T,0,0,==); 52 CHECK_MPZ(T,0,0,!=); 53 ASSERT_ALWAYS(T(6)<<2==6.*4); 54 ASSERT_ALWAYS(T(6)>>2==6./4); 55 ASSERT_ALWAYS(T(-13)<<2==-13.*4); 56 ASSERT_ALWAYS(T(-13)>>2==-13./4); 57 ASSERT_ALWAYS(++T(7)==8); 58 ASSERT_ALWAYS(++T(-8)==-7); 59 ASSERT_ALWAYS(--T(8)==7); 60 ASSERT_ALWAYS(--T(-7)==-8); 61 ASSERT_ALWAYS(+T(7)==7); 62 ASSERT_ALWAYS(+T(-8)==-8); 63 ASSERT_ALWAYS(-T(7)==-7); 64 ASSERT_ALWAYS(-T(-8)==8); 65 ASSERT_ALWAYS(abs(T(7))==7); 66 ASSERT_ALWAYS(abs(T(-8))==8); 67 ASSERT_ALWAYS(sgn(T(0))==0); 68 ASSERT_ALWAYS(sgn(T(9))==1); 69 ASSERT_ALWAYS(sgn(T(-17))==-1); 70 ASSERT_ALWAYS(T(1)+DBL_MAX>2); 71 ASSERT_ALWAYS(T(1)+DBL_MIN>1); 72 ASSERT_ALWAYS(T(1)+DBL_MIN<1.001); 73 ASSERT_ALWAYS(T(1)+std::numeric_limits<double>::denorm_min()>1); 74 ASSERT_ALWAYS(T(1)+std::numeric_limits<double>::denorm_min()<1.001); 75} 76 77int 78main (void) 79{ 80 tests_start(); 81 82 // Enough precision for 1 + denorm_min 83 mpf_set_default_prec(DBL_MANT_DIG-DBL_MIN_EXP+42); 84 checkqf<mpq_class>(); 85 checkqf<mpf_class>(); 86 87 tests_end(); 88 return 0; 89} 90