Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-21 Thread Mark J. Reed
On Thu, Nov 20, 2008 at 4:25 PM, Wolfgang Laun [EMAIL PROTECTED] wrote: So, calling sqrt with a real 0, should not come back with a complex number. Again, I think this should depend on context. In Perl5, simply use'ing Math::Complex changes the behavior of sqrt such that sqrt(-1) returns i.

RE: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Wolfgang Laun
: Mittwoch, 19. November 2008 22:24 To: [EMAIL PROTECTED] Subject: Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex Moritz (), Carl (): masak what should the behaviour of sign($x) be when $x is complex? I'd argue that it's a Failure. Aye.

[perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Carl Mäsak
# New Ticket Created by Carl Mäsak # Please include the string: [perl #60674] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60674 masak what should the behaviour of sign($x) be when $x is complex? masak rakudo: say

[perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Moritz Lenz via RT
On Wed Nov 19 07:35:48 2008, masak wrote: masak what should the behaviour of sign($x) be when $x is complex? I'd argue that it's a Failure. If you care about complex numbers, you usually want an angle instead, which you can get with Complex.polar. (And it's easier to give it a another meaning

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Carl Mäsak
Wolfgang (): There is a definition for the signum function for a complex argument. sign( z ) = z / |z| for all z != 0 sign( 0 ) = 0 See e.g. http://en.wikipedia.org/wiki/Sign_function Shouldn't be too difficult to implement. It isn't, and note that I also proposed it in my first email. I

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Mark J. Reed
On Thu, Nov 20, 2008 at 8:34 AM, Carl Mäsak [EMAIL PROTECTED] wrote: I guess the question is more about the programmer's expectations. Is this a case where we serve the programmer better by returning Failure, or by generalizing the Csign function to the complex plane? This is parallel to the

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Carl Mäsak
Mark (): I think the most sensible thing is to be consistent. sgn() fails for non-real input as long as sqrt() returns NaN for negative input. Change the latter behavior (via a pragma or whatever) so that sqrt() returns complex numbers, and then sgn() should start behaving on such numbers.

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Larry Wall
On Thu, Nov 20, 2008 at 04:31:22PM +0100, Carl Mäsak wrote: : Mark (): : I think the most sensible thing is to be consistent. sgn() fails for : non-real input as long as sqrt() returns NaN for negative input. : Change the latter behavior (via a pragma or whatever) so that sqrt() : returns

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Chris Dolan
Mark (): I think the most sensible thing is to be consistent. sgn() fails for non-real input as long as sqrt() returns NaN for negative input. Change the latter behavior (via a pragma or whatever) so that sqrt() returns complex numbers, and then sgn() should start behaving on such numbers.

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Mark J. Reed
I'd rather retain the dwimmishness of p5. $ perl -MMath::Complex -le 'print sqrt(-1)' i Note that I didn't have to pass in Math::Complex-make(-1,0). Just -1. On 11/20/08, Chris Dolan [EMAIL PROTECTED] wrote: Mark (): I think the most sensible thing is to be consistent. sgn() fails for

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread TSa
HaloO, Moritz Lenz via RT wrote: On Wed Nov 19 07:35:48 2008, masak wrote: masak what should the behaviour of sign($x) be when $x is complex? I'd argue that it's a Failure. This is a bit drastic. If one computes in the complex domain a complex valued sign function is appropriate. multi

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-20 Thread Wolfgang Laun
If a programmer calls a function with an argument that has a well-established type, s/he may very well expect a result according to that type, (considering that overloading isn't just a word for not caring about type). So, calling sqrt with a real 0, should not come back with a complex number.

Re: [perl #60674] sign($x) always returns 1 when $x ~~ Complex

2008-11-19 Thread Carl Mäsak
Moritz (), Carl (): masak what should the behaviour of sign($x) be when $x is complex? I'd argue that it's a Failure. Aye. [...]