Skip to content

Commit

Permalink
[calculation/additonal_results] Display scientific notation for negat…
Browse files Browse the repository at this point in the history
…ive integers
  • Loading branch information
GabrielNumworks authored and PiaNumworks committed Mar 25, 2024
1 parent fd16cf5 commit ea18e8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ bool AdditionalResultsType::HasScientificNotation(
calculationPreferences.numberOfSignificantDigits, globalContext);
return !historyResult.isIdenticalTo(
ScientificNotationHelper::ScientificLayout(
approximateOutput, globalContext, calculationPreferences));
approximateOutput, globalContext, calculationPreferences),
true);
}

bool AdditionalResultsType::HasInteger(const Expression exactOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Layout ScientificLayout(
assert(calculationPreferences.displayMode !=
Preferences::PrintFloatMode::Scientific);
Expression e;
if (a.type() == ExpressionNode::Type::BasedInteger) {
if (a.type() == ExpressionNode::Type::BasedInteger ||
(a.type() == ExpressionNode::Type::Opposite &&
a.childAtIndex(0).type() == ExpressionNode::Type::BasedInteger)) {
// Based Integer must be approximated to be layouted in scientific mode
ApproximationContext approximationContext(context);
e = Float<double>::Builder(
Expand Down
3 changes: 2 additions & 1 deletion apps/calculation/test/calculation_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,5 +931,6 @@ QUIZ_CASE(calculation_additional_results) {
&globalContext, &store);
assertCalculationAdditionalResultTypeHas("[[1+2i][3+i]]", {.matrix = true},
&globalContext, &store);
assertCalculationAdditionalResultTypeHas("-10", {}, &globalContext, &store);
assertCalculationAdditionalResultTypeHas("-10", {.scientificNotation = true},
&globalContext, &store);
}

0 comments on commit ea18e8a

Please sign in to comment.