From 5e43b5bba8bc926d6daae5dd7b88133687406376 Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Wed, 31 Jul 2024 02:25:03 +0200 Subject: [PATCH] units: Simplify units that convert to real numbers When we are given a value like `1_cm/in`, it is OK to pass it as input to the `sin` function or similar. Fixes: #1089 Signed-off-by: Christophe de Dinechin --- src/functions.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/functions.cc b/src/functions.cc index 0382d9c9..9dcaf357 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -195,9 +195,9 @@ algebraic_p function::evaluate(algebraic_r xr, id op, ops_t ops) } // Check if we need to deal with units specially - if (op == ID_sqrt || op == ID_cbrt) + if (unit_p u = x->as()) { - if (unit_p u = xr->as()) + if (op == ID_sqrt || op == ID_cbrt) { algebraic_g value = u->value(); algebraic_g uexpr = u->uexpr(); @@ -209,7 +209,13 @@ algebraic_p function::evaluate(algebraic_r xr, id op, ops_t ops) uexpr = pow(uexpr, exponent); return unit::make(value, uexpr); } - + save ueval(unit::mode, true); + x = x->evaluate(); + if (x && x->type() == ID_unit) + { + rt.inconsistent_units_error(); + return nullptr; + } } // Convert arguments to numeric if necessary