]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix some tests that fail with -fexcess-precision=standard
authorJonathan Wakely <jwakely@redhat.com>
Tue, 6 Jun 2023 15:09:29 +0000 (16:09 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 7 Jun 2023 15:51:59 +0000 (16:51 +0100)
libstdc++-v3/ChangeLog:

* testsuite/20_util/duration/cons/2.cc: Use values that aren't
affected by rounding.
* testsuite/20_util/from_chars/5.cc: Cast arithmetic result to
double before comparing for equality.
* testsuite/20_util/from_chars/6.cc: Likewise.
* testsuite/20_util/variant/86874.cc: Use values that aren't
affected by rounding.
* testsuite/25_algorithms/lower_bound/partitioned.cc: Compare to
original value instead of to floating-point-literal.
* testsuite/26_numerics/random/discrete_distribution/cons/range.cc:
Cast arithmetic result to double before comparing for equality.
* testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc:
Likewise.
* testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc:
Likewise.
* testsuite/26_numerics/valarray/transcend.cc (eq): Check that
the absolute difference is less than 0.01 instead of comparing
to two decimal places.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc:
Cast arithmetic result to double before comparing for equality.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc:
Likewise.
* testsuite/ext/random/hoyt_distribution/cons/parms.cc: Likewise.

16 files changed:
libstdc++-v3/testsuite/20_util/duration/cons/2.cc
libstdc++-v3/testsuite/20_util/from_chars/5.cc
libstdc++-v3/testsuite/20_util/from_chars/6.cc
libstdc++-v3/testsuite/20_util/variant/86874.cc
libstdc++-v3/testsuite/25_algorithms/lower_bound/partitioned.cc
libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc
libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc
libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc
libstdc++-v3/testsuite/26_numerics/valarray/transcend.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc
libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/parms.cc

index 95ec17be76ea3f4823afbedebcf98befb8b90f12..4ee07a9a9546dd37d7cdc58c6cd556182cb03fe6 100644 (file)
@@ -97,7 +97,7 @@ test01()
   duration<int, std::micro> d1_copy(d1);
   VERIFY(d1.count() * 1000 == d1_copy.count());
   
-  duration<double, std::micro> d2(8.0);
+  duration<double, std::micro> d2(85000);
   duration<double, std::milli> d2_copy(d2);
   VERIFY(d2.count() == d2_copy.count() * 1000.0);
   
@@ -105,7 +105,7 @@ test01()
   duration<int_emulator, std::micro> d3_copy(d3);
   VERIFY(d3.count() * 1000 == d3_copy.count());
   
-  duration<dbl_emulator, std::micro> d4(5.0);
+  duration<dbl_emulator, std::micro> d4(50000);
   duration<dbl_emulator, std::milli> d4_copy(d4);
   VERIFY(d4.count() == d4_copy.count() * dbl_emulator(1000.0));
 }
index db0976c33d38f593c3d4d4568f244e8a4e4caf9c..291ebf90fa09cb8e1a5a8e493b02af8577fa193f 100644 (file)
@@ -44,7 +44,7 @@ test01()
       r = std::from_chars(s.data(), s.data() + s.length(), d, fmt);
       VERIFY( r.ec == std::errc::invalid_argument );
       VERIFY( r.ptr == s.data() );
-      VERIFY( d == 3.2 );
+      VERIFY( d == (double) 3.2 );
     }
   }
 
@@ -57,7 +57,7 @@ test01()
       r = std::from_chars(s.data(), s.data() + s.length(), d, fmt);
       VERIFY( r.ec == std::errc::invalid_argument );
       VERIFY( r.ptr == s.data() );
-      VERIFY( d == 3.2 );
+      VERIFY( d == (double) 3.2 );
     }
   }
 
@@ -69,7 +69,7 @@ test01()
                        std::chars_format::scientific);
     VERIFY( r.ec == std::errc::invalid_argument );
     VERIFY( r.ptr == s.data() );
-    VERIFY( d == 3.2 );
+    VERIFY( d == (double) 3.2 );
   }
 
   // patterns that are invalid without the final character
@@ -83,7 +83,7 @@ test01()
       r = std::from_chars(s.data(), s.data() + s.length() - 1, d, fmt);
       VERIFY( r.ec == std::errc::invalid_argument );
       VERIFY( r.ptr == s.data() );
-      VERIFY( d == 3.2 );
+      VERIFY( d == (double) 3.2 );
     }
   }
 }
index 5a97bf6119a65be1e46a027c0450d38339fede13..1e3aa75beccae02f23707f8f804f1e0b8ddd3c9d 100644 (file)
@@ -39,7 +39,7 @@ test01()
   VERIFY( res.ptr == s.data() + s.length() );
   // std::from_chars should ignore the current rounding mode
   // and always round to nearest.
-  VERIFY( d == 0.1 );
+  VERIFY( d == (double) 0.1 );
 #endif
 #endif
 }
index 101056bc112c41cedd07aa9181503fb9bd1ff610..3e396b533111e7a30bc60b1d9945051520de80b8 100644 (file)
@@ -39,9 +39,9 @@ test02()
 void
 test03()
 {
-  std::variant<double, int> v1{1}, v2{2.3};
+  std::variant<double, int> v1{1}, v2{0.5};
   std::swap(v1, v2);
-  VERIFY( std::get<double>(v1) == 2.3 );
+  VERIFY( std::get<double>(v1) == 0.5 );
   VERIFY( std::get<int>(v2) == 1 );
 }
 
index 9e61337e2ada6af96689cc6690ab903e8a4d5e4d..557c1fada38eb0b9243a44ee0d19dc372ea033f2 100644 (file)
@@ -84,10 +84,10 @@ test02()
 
   auto part3 = std::lower_bound(c.begin(), c.end(), Y{1.0});
   VERIFY( part3 != c.end() );
-  VERIFY( part3->val == 1.2 );
+  VERIFY( part3->val == seq[1].val );
   auto part4 = std::lower_bound(c.begin(), c.end(), Y{1.0}, std::less<Y>{});
   VERIFY( part4 != c.end() );
-  VERIFY( part4->val == 1.2 );
+  VERIFY( part4->val == seq[1].val );
 }
 
 int
index 75db967084507e4f35c64d29e0ad74e029912b64..440fdc45686e10d2b926b3ea4f8017568597ca31 100644 (file)
@@ -33,8 +33,8 @@ test01()
   std::discrete_distribution<> u(wt.begin(), wt.end());
   std::vector<double> probablility = u.probabilities();
   VERIFY( probablility.size() == 5 );
-  VERIFY( probablility[0] == 0.5 / 6.0 );
-  VERIFY( probablility[2] == 2.5 / 6.0 );
+  VERIFY( probablility[0] == double(0.5 / 6.0) );
+  VERIFY( probablility[2] == double(2.5 / 6.0) );
 }
 
 int main()
index 114a5eea82710d6e1b2a5d1f0baea13b8de459a3..b9f4f733fa19a8ae91ee50fc2d261c375a1e73fa 100644 (file)
@@ -38,8 +38,8 @@ test01()
   VERIFY( interval[0] == 0.0 );
   VERIFY( interval[5] == 5.0 );
   VERIFY( density.size() == 5 );
-  VERIFY( density[0] == 0.5 / 6.0 );
-  VERIFY( density[2] == 2.5 / 6.0 );
+  VERIFY( density[0] == double(0.5 / 6.0) );
+  VERIFY( density[2] == double(2.5 / 6.0) );
 }
 
 int main()
index 01e291cd20e99e4dcf3ad68e665c4360b77a3f3e..95650b19d5e9f1c664e0d619a0f650307095756b 100644 (file)
@@ -39,7 +39,7 @@ test01()
   VERIFY( interval[5] == 5.0 );
   VERIFY( density.size() == 6 );
   VERIFY( density[0] == 0.0 );
-  VERIFY( density[4] == 3.5 / 8.5 );
+  VERIFY( density[4] == double(3.5 / 8.5) );
 }
 
 int main()
index 8288467311040bd8fbccc0bae05d4f542d8a42c9..19a17f3d8abf68487e708e0b46a30a9f4140315f 100644 (file)
@@ -22,7 +22,7 @@
 
 bool eq(double d, double e)
 {
-  return (int)(d * 100) == (int)(e * 100);
+  return std::abs(d - e) < 0.01;
 }
 
 void
index 78b6aaaf67f34798825c20aeb865f89100ff060e..cdb437c4c916841e794d2480993f0c960df7c626 100644 (file)
@@ -92,7 +92,7 @@ void test01() {
   is_03 >> ld1;
   VERIFY( ld1 == 66300.25 );
   is_03 >> d1;
-  VERIFY( d1 == .315 );
+  VERIFY( d1 == (double) .315 ); // N.B. cast removes excess precision
   is_03 >> f1;
   VERIFY( f1 == 1.5 );
 
index dd6d2dffc9d37a63edda6aba48956f45a72f8300..4ed4169a3f7dbb31a15b983a8b792fc1908e0692 100644 (file)
@@ -37,7 +37,7 @@ void test09()
   (is>>std::ws) >> c;
   (is>>std::ws) >> f2;
   VERIFY( f1 == 2456 );
-  VERIFY( f2 == 0.00567 );
+  VERIFY( f2 == (double) 0.00567 ); // N.B. cast removes excess precision
   VERIFY( c == '-' );
 }
 
index 3c73734cd23cf48b3335777d983d0b523721602a..9cf76ff37b25e46872336ba3d0da269a7da53dda 100644 (file)
@@ -95,7 +95,7 @@ void test10()
   VERIFY( f == 450.0 );
   is_04.ignore();
   is_04 >> f;
-  VERIFY( f == 0.005 );
+  VERIFY( f == (double) 0.005 ); // N.B. cast removes excess precision
   is_04 >> f;
   VERIFY( f == 6 );
   VERIFY( is_03.rdstate() == std::ios_base::eofbit );
index 843dfbaccfa993c3dbc68a0ba056ae727a11c602..6cfa476fc4617a4a51503dd94a937e8e45be8385 100644 (file)
@@ -90,7 +90,7 @@ void test01() {
   is_03 >> ld1;
   VERIFY( ld1 == 66300.25 );
   is_03 >> d1;
-  VERIFY( d1 == .315 );
+  VERIFY( d1 == (double) .315 ); // N.B. cast removes excess precision
   is_03 >> f1;
   VERIFY( f1 == 1.5 );
 
index 8c614197faf88c9db9035a1b67b346cf75c8c0d8..511a33cb21a93800769d16cd56bb308df4b65e6a 100644 (file)
@@ -35,7 +35,7 @@ void test09()
   (is >> std::ws) >> c;
   (is >> std::ws) >> f2;
   VERIFY( f1 == 2456 );
-  VERIFY( f2 == 0.00567 );
+  VERIFY( f2 == (double) 0.00567 ); // N.B. cast removes excess precision
   VERIFY( c == L'-' );
 }
 
index 3be2b023b5ff706272a1e7584cc0acb9ffe1a662..f2da3edea48b8519e20d4a7356f4b4b2e3161a51 100644 (file)
@@ -93,7 +93,7 @@ void test10()
   VERIFY( f == 450.0 );
   is_04.ignore();
   is_04 >> f;
-  VERIFY( f == 0.005 );
+  VERIFY( f == (double) 0.005 ); // N.B. cast removes excess precision
   is_04 >> f;
   VERIFY( f == 6 );
   VERIFY( is_03.rdstate() == std::ios_base::eofbit );
index 58d880a12d908527dc71ae3e5238aea72b442e3d..12af5f42450d77ff458c54b65a4a802f53a589d1 100644 (file)
@@ -27,7 +27,7 @@ void
 test01()
 {
   __gnu_cxx::hoyt_distribution<> u(0.05, 3.0);
-  VERIFY( u.q() == 0.05 );
+  VERIFY( u.q() == (double) 0.05 );
   VERIFY( u.omega() == 3.0 );
   VERIFY( u.min() == 0.0 );
   typedef __gnu_cxx::hoyt_distribution<>::result_type result_type;