Skip to content

Commit

Permalink
More improvements and it passes 6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Mar 19, 2009
1 parent f8d7a3e commit fb7d44d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/builtins/math.pir
Expand Up @@ -28,10 +28,13 @@ Returns the $N roots of a Complex number $z.
.local num pi
.local num z
.local num frac
pi = 3.14159
pi = 3.1415926
roots = new 'FixedPMCArray'
roots = n

# $P5 = new 'Complex'
# $P5[1] = 1

if n > 0 goto positive
.return ('NaN')
positive:
Expand All @@ -41,19 +44,23 @@ Returns the $N roots of a Complex number $z.
general:
div $N0, 1, n
frac = $N0
$N1 = pow x, frac
$N4 = abs x
$N1 = pow $N4, frac
$I0 = 0
loop:
if $I0 >= n goto done
$P2 = new 'Complex'
$N3 = $N0
$N3 = frac
$N3 *= 2
$N3 *= pi
$I0 = 0
loop:
if $I0 >= n goto done
$N3 *= $I0
$P2[1] = $N3
$P2 = $P2.'exp'()
$P2 *= $N1
roots[$I0] = $N3
if x > 0 goto assign
# $P2 *= $P5
assign:
roots[$I0] = $P2
inc $I0
goto loop
done:
Expand Down

0 comments on commit fb7d44d

Please sign in to comment.