From 5de6eb0fe2c09dcc7decebf027085a2efbc92dfd Mon Sep 17 00:00:00 2001 From: Joseph Elliott Hand Date: Fri, 1 May 2026 14:47:27 -1000 Subject: Fix units in denominator without exponents not being inverted Signed-off-by: Joseph Elliott Hand --- unit.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unit.h b/unit.h index fdb5a9a..a4c8b9d 100644 --- a/unit.h +++ b/unit.h @@ -169,7 +169,7 @@ get_unit_value(char const * string) { for (; i < token_count;) { if (tokens[i].type == ONE) { - if (i == 0 && tokens[1].type == SLASH) { + if (i == 0 && token_count > 1 && tokens[1].type == SLASH) { exp_sign = -1.0; i += 2; continue; @@ -241,13 +241,13 @@ get_unit_value(char const * string) { unit_found: - if (tokens[i + 1].type != EXP) { - value *= unit_value; + if (token_count <= i+1 || tokens[i + 1].type != EXP) { + value *= pow(unit_value, exp_sign); i += 1; continue; } - if (tokens[i + 2].type != NUMBER) goto error; + if (token_count <= i+2 || tokens[i + 2].type != NUMBER) goto error; value *= pow(unit_value, exp_sign * tokens[i + 2].value.num); i += 3; -- cgit v1.2.3