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.

Reply via email to