From cc142b2df4b30f427b73ff45cdc18f3d51e8b844 Mon Sep 17 00:00:00 2001 From: Cade Mack <24661281+cademack@users.noreply.github.com> Date: Wed, 12 Feb 2025 09:36:33 -0500 Subject: [PATCH] 22800: Fixes an issue where the absolute value of (null) returns zero (#352) --- src/Amalgam/entity/Entity.h | 2 +- src/Amalgam/interpreter/Interpreter.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Amalgam/entity/Entity.h b/src/Amalgam/entity/Entity.h index 0df7d827..62b18755 100644 --- a/src/Amalgam/entity/Entity.h +++ b/src/Amalgam/entity/Entity.h @@ -325,7 +325,7 @@ class Entity //Evaluates the specified label into a string and puts the value in value_out. //If the label exists, sets value_out to the value and returns true. // Otherwise sets value_out to empty string and returns false - std::pair GetValueAtLabelAsString(StringInternPool::StringID label_sid, bool on_self = false); + std::pair GetValueAtLabelAsString(StringInternPool::StringID label_sid, bool on_self = false); //Evaluates the specified label into a EvaluableNodeImmediateValueWithType //if destination_temp_enm is not null and code is needed, it will make a copy diff --git a/src/Amalgam/interpreter/Interpreter.h b/src/Amalgam/interpreter/Interpreter.h index a41b5030..bbdc1bb5 100644 --- a/src/Amalgam/interpreter/Interpreter.h +++ b/src/Amalgam/interpreter/Interpreter.h @@ -515,7 +515,7 @@ class Interpreter return InterpretNode(n, immediate_result); } - //computes a unary numeric function on the given node + //computes a unary numeric function on the given node, returns an ENT_NULL if n is interpreted as an ENT_NULL __forceinline EvaluableNodeReference InterpretNodeUnaryNumericOperation(EvaluableNode *n, bool immediate_result, std::function func) { @@ -526,6 +526,8 @@ class Interpreter } auto retval = InterpretNodeIntoUniqueNumberValueOrNullEvaluableNode(n); + if(retval->GetType() == ENT_NULL) + return retval; double value = retval->GetNumberValue(); double result = func(value); retval->SetTypeViaNumberValue(result);