Skip to content

Commit

Permalink
Merge pull request #947 from drgrice1/bugfix/compute-reals-only-strin…
Browse files Browse the repository at this point in the history
…gs-better

Alternate to #946 and probably better (slightly) approach.
  • Loading branch information
pstaabp authored Oct 30, 2023
2 parents f339a70 + 4344e32 commit 0cade7c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions macros/core/Parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ =head2 Compute
# ^uses Formula
# ^uses Value::contextSet
sub Compute {
my $string = shift;
my $formula = Formula($string);
if (Value::matchNumber($string)) {
my $real = Real($string);
my $string = shift;
if ($string =~ m/^\s*-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]\d+)\s*$/
&& Value::matchNumber($string)
&& ($string ^ $string) eq '0')
{
warn "Compute() called with ambiguous value: $string\n"
. '-- use Real() for scientific notation'
. " ($real) or use Formula() for $formula \n"
unless ($real == $formula);
return $real;
. "-- use Real() for scientific notation or Formula() for Euler's number e\n";
$string = uc($string);
}
my $formula = Formula($string);
$formula = $formula->{tree}->Compute if $formula->{tree}{canCompute};
my $context = $formula->context;
my $flags = Value::contextSet($context, reduceConstants => 0, reduceConstantFunctions => 0, showExtraParens => 0);
Expand Down

0 comments on commit 0cade7c

Please sign in to comment.