Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitute incorrectly handles negative numbers when reduceConstants is set to 0 #658

Closed
dlglin opened this issue Feb 28, 2022 · 1 comment

Comments

@dlglin
Copy link
Member

dlglin commented Feb 28, 2022

See the attached MWE. If reduceConstants is set to 0, when a negative number is substituted into a formula, the parentheses are removed in the LaTeX string.

e.g.
Context() -> flags -> set(reduceConstants => 0);
$f = Formula("x^2");
$g = $f->substitute(x=>-3);

The value of $g is 9, but the LaTeX string for $g is "-3^2", which causes two issues:

  1. $g is displayed incorrectly (without the parentheses) when shown on screen.
  2. If $g is used in a subsequent calculation, then the LaTeX string is used, which leads to incorrect values. e.g. $g-1 evaluates to -10

reduceConstantsIssue.pg.txt

dpvc added a commit to dpvc/pg that referenced this issue Mar 1, 2022
pstaabp added a commit that referenced this issue Mar 12, 2022
Make sure negative numbers are handled as a negated number in Value items (#658)
@pstaabp
Copy link
Sponsor Member

pstaabp commented Jul 7, 2022

#659 now fixes this.

@pstaabp pstaabp closed this as completed Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants