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

&infix:<**>( Complex, UInt ) is inaccurate #5876

Closed
p6rt opened this issue Dec 8, 2016 · 4 comments
Closed

&infix:<**>( Complex, UInt ) is inaccurate #5876

p6rt opened this issue Dec 8, 2016 · 4 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Dec 8, 2016

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

Searchable as RT130299$

@p6rt
Copy link
Author

@p6rt p6rt commented Dec 8, 2016

From @b2gills

  say i ** 3; # -1.83697019872103e-16-1i

  say i * i * i; # -0-1i

  my Complex $acc;
  $acc *= i for 1..3;
  say $acc; # -0-1i

Currently it is handled by

  multi sub infix​:<**>(Complex​:D \a, Num(Real) \b) returns Complex​:D {
  b == 0e0 ?? Complex.new(1e0, 0e0) !! (b * a.log).exp
  }

Which I think would be necessary for negative Ints ( I don't know enough about Complex numbers )

I came across this when creating a golf entry for https://codegolf.stackexchange.com/questions/102059/complex-binary-numbers/102523#102523

  *.base(2).comb(/1+/).map(i***.chars).sum

I had to go with the following instead

  *.base(2).comb(/1+/).map({[*] i xx.chars}).sum

@p6rt
Copy link
Author

@p6rt p6rt commented Dec 8, 2016

From @zoffixznet

On Thu, 08 Dec 2016 07​:45​:18 -0800, brad wrote​:

say i ** 3; # -1.83697019872103e-16-1i

say i * i * i; # -0-1i

my Complex $acc;
$acc *= i for 1..3;
say $acc; # -0-1i

Currently it is handled by

multi sub infix​:<**>(Complex​:D \a, Num(Real) \b) returns Complex​:D {
b == 0e0 ?? Complex.new(1e0, 0e0) !! (b * a.log).exp
}

Which I think would be necessary for negative Ints ( I don't know
enough about Complex numbers )

I came across this when creating a golf entry for
https://codegolf.stackexchange.com/questions/102059/complex-binary-
numbers/102523#​102523

*.base(2).comb(/1+/).map(i***.chars).sum

I had to go with the following instead

*.base(2).comb(/1+/).map({[*] i xx.chars}).sum

As discussed on IRC https://irclog.perlgeek.de/perl6/2016-12-08#i_13705128 the current result is accurate, it's just not perfectly precise to give the -0-i answer.

Perl 5's Math​::Complex also gives the same noisy answer.

I've tried a couple of different algos that result in -0-i, but the fastest of them made the calculation 60x slower (others going as slow as 508x slower).

So I'm closing this as a won't-fix.

@p6rt
Copy link
Author

@p6rt p6rt commented Dec 8, 2016

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

@p6rt
Copy link
Author

@p6rt p6rt commented Dec 8, 2016

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

@p6rt p6rt closed this Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant