public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] std::polar requires non-negative rho
@ 2015-05-13 13:36 Jonathan Wakely
  2015-05-13 13:41 ` Daniel Krügler
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2015-05-13 13:36 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 148 bytes --]

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2459

Voted into the WP in Lenexa.

Tested powerpc64le-linux, comitted to trunk.

[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 805 bytes --]

commit 9bf3b9ea20334711ecdced656323f69959521a82
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 13 14:18:03 2015 +0100

    	* include/std/complex (polar): Check for negative rho (LWG 2459).

diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index 585683c..f2a6cf9 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -667,7 +667,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     inline complex<_Tp>
     polar(const _Tp& __rho, const _Tp& __theta)
-    { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
+    {
+      _GLIBCXX_DEBUG_ASSERT( __rho >= 0 );
+      return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta));
+    }
 
   template<typename _Tp>
     inline complex<_Tp>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] std::polar requires non-negative rho
  2015-05-13 13:36 [patch] std::polar requires non-negative rho Jonathan Wakely
@ 2015-05-13 13:41 ` Daniel Krügler
  2015-05-13 14:03   ` Jonathan Wakely
  2015-05-13 14:11   ` Marc Glisse
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Krügler @ 2015-05-13 13:41 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches List

2015-05-13 15:32 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2459
>
> Voted into the WP in Lenexa.
>
> Tested powerpc64le-linux, comitted to trunk.

What about assertions regarding non-NAN rho and finite theta, as
decided for by the LWG 2439?

- Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] std::polar requires non-negative rho
  2015-05-13 13:41 ` Daniel Krügler
@ 2015-05-13 14:03   ` Jonathan Wakely
  2015-05-13 14:11   ` Marc Glisse
  1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2015-05-13 14:03 UTC (permalink / raw)
  To: Daniel Krügler; +Cc: libstdc++, gcc-patches List

On 13/05/15 15:36 +0200, Daniel Krügler wrote:
>2015-05-13 15:32 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2459
>>
>> Voted into the WP in Lenexa.
>>
>> Tested powerpc64le-linux, comitted to trunk.
>
>What about assertions regarding non-NAN rho and finite theta, as
>decided for by the LWG 2439?

I don't know how to reliably test those conditions. What if _Tp is not
a floating-point type?

The assertion I added addresses the original issue as reported
numerous times to libc++. I don't really care if it doesn't deal with
the additional preconditions added in Cologne, as users don't seem to
expect a meaningful answer for NaNs and infinities.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] std::polar requires non-negative rho
  2015-05-13 13:41 ` Daniel Krügler
  2015-05-13 14:03   ` Jonathan Wakely
@ 2015-05-13 14:11   ` Marc Glisse
  2015-05-13 17:08     ` Daniel Krügler
  1 sibling, 1 reply; 5+ messages in thread
From: Marc Glisse @ 2015-05-13 14:11 UTC (permalink / raw)
  To: Daniel Krügler; +Cc: Jonathan Wakely, libstdc++, gcc-patches List

On Wed, 13 May 2015, Daniel KrÃŒgler wrote:

> 2015-05-13 15:32 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4383.html#2459
>>
>> Voted into the WP in Lenexa.
>>
>> Tested powerpc64le-linux, comitted to trunk.
>
> What about assertions regarding non-NAN rho and finite theta, as
> decided for by the LWG 2439?

non-NAN rho is already covered by rho >= 0.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] std::polar requires non-negative rho
  2015-05-13 14:11   ` Marc Glisse
@ 2015-05-13 17:08     ` Daniel Krügler
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Krügler @ 2015-05-13 17:08 UTC (permalink / raw)
  To: libstdc++; +Cc: Jonathan Wakely, gcc-patches List

2015-05-13 16:05 GMT+02:00 Marc Glisse <marc.glisse@inria.fr>:
> On Wed, 13 May 2015, Daniel Krügler wrote:
>> What about assertions regarding non-NAN rho and finite theta, as
>> decided for by the LWG 2439?
>
> non-NAN rho is already covered by rho >= 0.

Agreed on that.

- Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-13 17:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 13:36 [patch] std::polar requires non-negative rho Jonathan Wakely
2015-05-13 13:41 ` Daniel Krügler
2015-05-13 14:03   ` Jonathan Wakely
2015-05-13 14:11   ` Marc Glisse
2015-05-13 17:08     ` Daniel Krügler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).