Skip to content

Commit

Permalink
- Fixed a minor bug inside the Parser
Browse files Browse the repository at this point in the history
Example:
	var i = 0
	var result
	i = 42

Will parse correctly now, even when the semicolons are missing.

modified:   scripts/lanczos_approximation.sf
  • Loading branch information
trizen committed Nov 22, 2015
1 parent 411448b commit 451f169
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/Sidef/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ package Sidef::Parser {
}
}

defined($end_delim) && (/\G\h*,\h*/gc || last);
(defined($end_delim) && /\G\h*,\h*/gc) || last;
$self->parse_whitespace(code => $opt{code});
}

Expand Down Expand Up @@ -749,7 +749,7 @@ package Sidef::Parser {
}

push @var_objs, $obj;
defined($end_delim) && (/\G\h*,\h*/gc || last);
(defined($end_delim) && /\G\h*,\h*/gc) || last;
$self->parse_whitespace(code => $opt{code});
}

Expand Down
21 changes: 9 additions & 12 deletions scripts/lanczos_approximation.sf
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@ func gamma(z) {
12.507343278686905, -0.13857109526572012,
9.9843695780195716e-6, 1.5056327351493116e-7,
]
z = Complex(z)

var result;
const pi = Complex.pi;
const one = Complex(1);
var result
z = Complex(z)
const pi = Complex.pi

if (z.real < 0.5) {
result = (pi / (sin(pi * z) * gamma(one - z)))
result = (pi / (sin(pi * z) * gamma(Complex(1) - z)))
}
else {
z -= one
z--
var x = 0.99999999999980993

var i = Complex(0);
p.each { |pval|
x += pval/(z + i + one)
i.inc!
p.each_with_index { |i, v|
x += v/(z + i + 1)
}

var t = (z + len(p) - 0.5);
result = (sqrt(pi*2) * t**(z+0.5) * exp(-t) * x);
var t = (z + p.len - 0.5)
result = (sqrt(pi*2) * t**(z+0.5) * exp(-t) * x)
}

withinepsilon(result.im) ? result.real : result
Expand Down

0 comments on commit 451f169

Please sign in to comment.