Skip to content

contextFraction interaction with changing Context()->{format}{number} #1340

@somiaj

Description

@somiaj

Consider the following example problem (I have a problem that mixes fractions and decimals, and I wanted the decimals to all be rounded to three decimal digits that this came from).

DOCUMENT();
loadMacros(qw(PGstandard.pl contextFraction.pl PGML.pl));

Context('Fraction');
Context()->{format}{number} = "%.3g";
$x = Fraction('27375/17');
BEGIN_PGML
[`[$x]`]
END_PGML
ENDDOCUMENT();

This problem gives the error:

ERRORS from evaluating PG file:
Fraction numerators must be integers at line 1 of (eval 1729)
   from within Value::Error called at line 855 of [PG]/macros/contexts/contextFraction.pl
   from within context::Fraction::Value::Fraction::new called at line 1 of (eval 1729)
   from within main::Fraction called at line 6 of undefined

The issue I ran into was a little different, where fractions where being printed using SI notation, as in this example.

DOCUMENT();
loadMacros(qw(PGstandard.pl contextFraction.pl PGML.pl));

Context('Fraction');
Context()->{format}{number} = "%.3g";
$x = Fraction('11/70') / Fraction('3/55') * 40;
BEGIN_PGML
[`[$x]`]
END_PGML
ENDDOCUMENT();

The faction should have been 2420/21 and if I create the fraction with Fraction('2420') / Fraction('21') I don't see an issue, but creating it using fraction operations did cause the fraction to be displayed using SI notation, 2.42E+3/21.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions