units: Keep power integral

When we compute powers for units with numerical results on, we may end
up with decimal powers in units for no reason.

Spotted by displaying the result of an `EvalEq` with `FIX 2`.

Fixes: #1086

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2024-07-30 23:11:34 +02:00
parent 4ecde93aaa
commit 631fa8f6f3
2 changed files with 2 additions and 0 deletions

View file

@ -1260,6 +1260,7 @@ algebraic_p expression::simplify_products() const
// Save auto-simplify and set it, and evaluate units normally
settings::SaveAutoSimplify sas(true);
settings::SaveNumericalResults snr(false);
save<bool> smode(unit::mode, false);
save<bool> sexpr(unit::factoring, true);

View file

@ -205,6 +205,7 @@ algebraic_p function::evaluate(algebraic_r xr, id op, ops_t ops)
uint divisor = 2 + (op == ID_cbrt);
algebraic_g exponent = +fraction::make(integer::make(1),
integer::make(divisor));
settings::SaveNumericalResults snr(false);
uexpr = pow(uexpr, exponent);
return unit::make(value, uexpr);
}