Skip to content
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

Cannot declare a Complex number without i #2047

Closed
p6rt opened this issue Aug 10, 2010 · 5 comments
Closed

Cannot declare a Complex number without i #2047

p6rt opened this issue Aug 10, 2010 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Aug 10, 2010

Migrated from rt.perl.org#77126 (status was 'rejected')

Searchable as RT77126$

@p6rt
Copy link
Author

p6rt commented Aug 10, 2010

From A_M_C@bigpond.net.au

michael@​wslx1​:working> perl6 -v

This is Rakudo Perl 6, version 2010.07-47-g9fd5eaa built on parrot 2.6.0

Copyright 2008-2010, The Perl Foundation

The following

my Complex $c = 1;

fails at runtime with the error message

Type check failed for assignment
  in '&infix​:<=>' at line 1
  in main program body at line 13​:t.p6

Declaring it as

my Complex $c = 1 + 0i;

works OK.

The following is acceptable

my Complex $c = 1i;
say $c; # 0 + 1i

as is

my Rat $r = 1.0;
my Complex $c = 1 + 0i;
say $c + $r; # 2 + 0i

For consistency it should be possible to leave out the imaginary value
from a Complex declaration where it is 0.

Regards,
Michael

@p6rt
Copy link
Author

p6rt commented Aug 10, 2010

From @moritz

On Tue Aug 10 01​:28​:11 2010, A_M_C@​bigpond.net.au wrote​:

my Complex $c = 1;

fails at runtime with the error message

Type check failed for assignment
in '&infix​:<=>' at line 1
in main program body at line 13​:t.p6

This conforms to the current specification. If you want something that
accepts both Complex and Real numbers, use 'Numeric' as type constraint.

Please notice that numeric type hierarchy in Perl 6 is not based on
subset types (as the mathematical hierarchy is), mostly for performance
reasons.

Note that in order not to surprise the casual programmar, (-1).sqrt
fails, while (-1 + 0i).sqrt returns one of the complex square roots.
The idea is that if you know about Complex numbers, you know what you're
doing.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Aug 10, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 10, 2010

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Aug 10, 2010
@p6rt
Copy link
Author

p6rt commented Aug 11, 2010

From A_M_C@bigpond.net.au

Thanks Moritz,

it just felt like I should be able to leave out the "+ 0i" since that's
how I wrote them when studying maths;)

Thanks for the shiny new toy;)

Regards,
Michael

On 11/08/10 00​:59, Moritz Lenz via RT wrote​:

On Tue Aug 10 01​:28​:11 2010, A_M_C@​bigpond.net.au wrote​:

my Complex $c = 1;

fails at runtime with the error message

Type check failed for assignment
in '&infix​:<=>' at line 1
in main program body at line 13​:t.p6

This conforms to the current specification. If you want something that
accepts both Complex and Real numbers, use 'Numeric' as type constraint.

Please notice that numeric type hierarchy in Perl 6 is not based on
subset types (as the mathematical hierarchy is), mostly for performance
reasons.

Note that in order not to surprise the casual programmar, (-1).sqrt
fails, while (-1 + 0i).sqrt returns one of the complex square roots.
The idea is that if you know about Complex numbers, you know what you're
doing.

Cheers,
Moritz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant