Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions macros/contexts/contextSignificantFigures.pl
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ sub ROUND {
return sprintf("%.0E", $x + $d) - $d;
}

package context::SignificantFigures::BOP::parse;
our @ISA = ("Parser::BOP");
use Data::Dumper;
sub _check {
my $self = @_;
my ($lop, $rop) = ($self->{lop}, $self->{rop});
print Dumper 'in _check';
print Dumper [$self, ref $lop, ref $rop];


}

sub _eval {
my ($self, $a, $b) = @_;
print Dumper [ref $self, $a->value, ref $b->value];
return $self->package('SignificantFigures')->new("$_[0]E$_[1]");
}

package context::SignificantFigures;

sub Init {
Expand All @@ -352,6 +370,10 @@ sub new {
$context->{precedence}{SignifcantFigures} = $context->{precedence}{special};
$context->flags->set(limits => [ -1000, 1000, 1 ]);

$context->operators->add(
'x 10^' => { class => 'context::SignificantFigures::BOP::parse'}
);

return $context;
}

Expand Down Expand Up @@ -386,4 +408,5 @@ sub perl {
return $self->context->Package('Real') . '->new(' . $value->value . ',' . $value->N . ')';
}


1;
21 changes: 21 additions & 0 deletions t/contexts/sigfig2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use Test2::V0 '!E', { E => 'EXISTS' };

die "PG_ROOT not found in environment.\n" unless $ENV{PG_ROOT};
do "$ENV{PG_ROOT}/t/build_PG_envir.pl";

use lib "$ENV{PG_ROOT}/lib";

loadMacros('contextSignificantFigures.pl');

use Value;
require Parser::Legacy;
import Parser::Legacy;

use Data::Dumper;

Context('SignificantFigures');

subtest 'Entering sigfig in sci notation' => sub {
my $a1 = Compute('1.0 x 10^2');
is $a1->format('E'), '1.0E+02', 'Ensure that the internal storage of 1.0 * 10^2 is correct.';
};
Loading