[PATCH] PR libstdc++/61761 fix std::proj for targets without C99 cproj

Jonathan Wakely jwakely@redhat.com
Fri May 3 19:25:00 GMT 2019


On 03/05/19 14:34 +0000, Szabolcs Nagy wrote:
>On 03/05/2019 13:08, Jonathan Wakely wrote:
>> On 03/05/19 11:21 +0000, Szabolcs Nagy wrote:
>>> On 03/05/2019 12:16, Jonathan Wakely wrote:
>>>> Hmm, which file in the source tree does the include/cmath symlink in
>>>> the build tree point to?
>>>
>>> /work/b/build-aarch64-none-elf/obj/gcc2/aarch64-none-elf/libstdc++-v3$ ls -l include/cmath
>>> lrwxrwxrwx 1 szabolcs szabolcs 51 May  1 18:06 include/cmath -> /work/b/src/gcc/libstdc++-v3/include/c_global/cmath
>>
>>
>> Oh, I see the problem. <complex> and <cmath> both guard use of
>> copysign by _GLIBCXX_USE_C99_MATH_TR1 but the test just uses it
>> unconditionally.
>>
>> Does the attached patch work?
>
>it fails because copysign takes two arguments,
>once that is fixed the test compiles.
>thanks.

Doh! I'll commit the working version (attached).


>there is still an execution failure, but that's not
>related to copysign: proj(i*inf) returns i*inf instead of inf
>i haven't figured out why:
>
>/work/b/src/gcc/libstdc++-v3/testsuite/26_numerics/complex/proj.cc:105: void test01(): Assertion 'eq( std::proj(c0p) ,
>std::complex<double>(pinf, +0.0) )' failed.
>FAIL: 26_numerics/complex/proj.cc execution test

If std::copysign isn't avilable then we only provide the generic
std::proj which doesn't support infinities, so all the tests using
positive or negative infinity will give the wrong answer.

The r270759 change doesn't actually use std::copysign, only
__builtin_copysign, but if the compiler doesn't expand that then it
still requires libc to provide copysign. If autoconf decides copysign
isn't available, std::proj doesn't support infinities.

I'm not sure whether to XFAIL the test in that case, or just make the
tests for infinities conditional on the necessary support in libc e.g.

--- a/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
@@ -101,6 +101,7 @@ test01()
   VERIFY( eq( std::proj(cqq)  , cqq ) );
   VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
   const std::complex<double> c0p(0, pinf);
   VERIFY( eq( std::proj(c0p)  , std::complex<double>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-c0p) , std::complex<double>(pinf, -0.0) ) );
@@ -164,6 +165,7 @@ test01()
   const std::complex<double> cnp(ninf, pinf);
   VERIFY( eq( std::proj(cnp)  , std::complex<double>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-cnp) , std::complex<double>(pinf, -0.0) ) );
+#endif
 }

 void
@@ -215,6 +217,7 @@ test02()
   VERIFY( eq( std::proj(cqq)  , cqq ) );
   VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
   const std::complex<float> c0p(0, pinf);
   VERIFY( eq( std::proj(c0p)  , std::complex<float>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-c0p) , std::complex<float>(pinf, -0.0) ) );
@@ -278,6 +281,7 @@ test02()
   const std::complex<float> cnp(ninf, pinf);
   VERIFY( eq( std::proj(cnp)  , std::complex<float>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-cnp) , std::complex<float>(pinf, -0.0) ) );
+#endif
 }

 void
@@ -329,6 +333,7 @@ test03()
   VERIFY( eq( std::proj(cqq)  , cqq ) );
   VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
   const std::complex<long double> c0p(0, pinf);
   VERIFY( eq( std::proj(c0p)  , std::complex<long double>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-c0p) , std::complex<long double>(pinf, -0.0) ) );
@@ -392,6 +397,7 @@ test03()
   const std::complex<long double> cnp(ninf, pinf);
   VERIFY( eq( std::proj(cnp)  , std::complex<long double>(pinf, +0.0) ) );
   VERIFY( eq( std::proj(-cnp) , std::complex<long double>(pinf, -0.0) ) );
+#endif
 }

 int



-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-patch
Size: 1766 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190503/41255c95/attachment.bin>


More information about the Libstdc++ mailing list