@@ -141,7 +141,8 @@ public static Expression Parse(Simulation simulation, IEnumerator<Token> tokens,
141141 private delegate Expression FunctionResolver ( Simulation simulation , IEnumerator < Token > tokens , ref Token ? token , Func < string , object ? > getVariableValue ) ;
142142
143143 private static readonly FrozenDictionary < string , FunctionResolver > BuiltInFunctions = FrozenDictionary . Create < string , FunctionResolver > ( Collation . Default , [
144- new ( "datalength" , ( simulation , tokens , ref token , getVariableValue ) => new DataLength( Expression . Parse ( simulation , tokens , ref token , getVariableValue ) ) )
144+ new ( "datalength" , ( simulation , tokens , ref token , getVariableValue ) => new DataLength( Expression . Parse ( simulation , tokens , ref token , getVariableValue ) ) ) ,
145+ new ( "abs" , ( simulation , tokens , ref token , getVariableValue ) => new AbsoluteValue( Expression . Parse ( simulation , tokens , ref token , getVariableValue ) ) ) ,
145146 ] ) ;
146147
147148 private sealed class NamedExpression ( Expression expression , string name ) : Expression
@@ -281,6 +282,22 @@ public sealed class DataLength(Expression source) : Expression
281282
282283#if DEBUG
283284 public override string ToString ( ) => $ "DATALENGTH({ source } )";
285+ #endif
286+ }
287+
288+ public sealed class AbsoluteValue ( Expression source ) : Expression
289+ {
290+ private readonly Expression source = source ;
291+
292+ public override object ? Run ( Func < List < string > , object ? > getColumnValue ) => source . Run ( getColumnValue ) switch
293+ {
294+ null => null ,
295+ int value => Math . Abs ( value ) ,
296+ _ => throw new NotSupportedException ( $ "Simulation unable to to run DATALENGTH function on the provided expression.") ,
297+ } ;
298+
299+ #if DEBUG
300+ public override string ToString ( ) => $ "ABS({ source } )";
284301#endif
285302 }
286303}
0 commit comments