New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sign($x) always returns 1 when $x ~~ Complex #419
Comments
From @masak<masak> what should the behaviour of sign($x) be when $x is complex? |
From @moritzOn Wed Nov 19 07:35:48 2008, masak wrote:
I'd argue that it's a Failure. (If you wanted a complex number with magnitude one, then you should call Cheers,
|
The RT System itself - Status changed from 'new' to 'open' |
From @masakMoritz (>), Carl (>>):
Aye.
|
From wolfgang.laun@gmail.comThere is a definition for the signum function for a complex argument. sign( z ) = z / |z| for all z != 0 See e.g. http://en.wikipedia.org/wiki/Sign_function Shouldn't be too difficult to implement. -----Original Message----- Moritz (>), Carl (>>):
Aye. |
From @masakWolfgang (>):
It isn't, and note that I also proposed it in my first email. I guess the question is more about the programmer's expectations. Is |
From @markjreedOn Thu, Nov 20, 2008 at 8:34 AM, Carl Mäsak <cmasak@gmail.com> wrote:
This is parallel to the case for sqrt($x) for $x<0. Which does not by On the one hand, as long as sqrt() *doesn't* uncomplainingly return On the other hand, a lot of code will be expecting the return value of I think the most sensible thing is to be consistent. sgn() fails for -- |
From @masakMark (>):
I like that. Both sign() and sqrt() will then behave like they usually // Carl |
From @TimToadyOn Thu, Nov 20, 2008 at 04:31:22PM +0100, Carl Mäsak wrote: Doesn't really need a pragma, just import an appropriate multi. Larry |
From @chrisdolan
Rather than a pragma, wouldn't it make more sense to have multi sub sgn(Num) -> Num behave appropriately for real numbers and multi sub sgn(Complex) -> Complex behave appropriately for complex numbers? So people who want sqrt(-1) be |
From @markjreedI'd rather retain the dwimmishness of p5. $ perl -MMath::Complex -le 'print sqrt(-1)' Note that I didn't have to pass in Math::Complex->make(-1,0). Just -1. On 11/20/08, Chris Dolan <chris@chrisdolan.net> wrote:
-- Mark J. Reed <markjreed@gmail.com> |
From Thomas.Sandlass@vts-systems.deHaloO, Moritz Lenz via RT wrote:
This is a bit drastic. If one computes in the complex domain multi sub sign(Complex $z --> Complex) That is, it returns a unit complex number or zero. This nicely Regards, TSa. "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare |
From wolfgang.laun@gmail.comIf a programmer calls a function with an argument that has a So, calling sqrt with a real < 0, should not come back with a complex On Thu, Nov 20, 2008 at 4:31 PM, Carl Mäsak <cmasak@gmail.com> wrote:
|
From @markjreedOn Thu, Nov 20, 2008 at 4:25 PM, Wolfgang Laun <wolfgang.laun@gmail.com> wrote:
Again, I think this should depend on context. In Perl5, simply So simply making sqrt a multi doesn't quite suffice.
Agreed. (Side topic: what about autodemotion? Should calling sqrt
My only objection to that behavior was that I want to avoid surprise -- |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in t/spec/S32-num/sign.t commit 82872635f7c3f0494a1291fa5b359ea56ee5cde5 [t/spec] test for RT #60674, sign(Complex) Inline Patchdiff --git a/t/spec/S32-num/sign.t b/t/spec/S32-num/sign.t
index 819943a..d04e35f 100644
--- a/t/spec/S32-num/sign.t
+++ b/t/spec/S32-num/sign.t
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 14;
+plan *;
# L<S32::Numeric/Num/"=item sign">
@@ -29,5 +29,8 @@ is(sign(NaN),NaN, 'sign of NaN is NaN');
}
ok sign(undef) ~~ undef, 'sign(undef) is undef';
+ok sign(3+4i) ~~ undef, 'sign(Complex) fails';
+
+done_testing;
# vim: ft=perl6 |
From @moritzAs per Rakudo 27e0d69c8f4927eb3df3087ca12b8b1cb616365f and spec Cheers, |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#60674 (status was 'resolved')
Searchable as RT60674$
The text was updated successfully, but these errors were encountered: