Skip to content

Commit

Permalink
Merge pull request #9 from LunarClient/add-sign-function
Browse files Browse the repository at this point in the history
  • Loading branch information
bernie-g authored Mar 7, 2024
2 parents 1fc5c7c + 4154af7 commit 0781cab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/com/eliotlash/molang/functions/classic/Sign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.eliotlash.molang.functions.classic;

import com.eliotlash.molang.ast.Expr;
import com.eliotlash.molang.functions.Function;
import com.eliotlash.molang.variables.ExecutionContext;

/**
* Absolute value function
*/
public class Sign extends Function {

public Sign(String name) {
super(name);
}

@Override
public int getRequiredArguments() {
return 1;
}

@Override
public double _evaluate(Expr[] arguments, ExecutionContext ctx) {
return Math.signum(this.evaluateArgument(arguments, ctx, 0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private static void addFunction(Map<FunctionDefinition, Function> map, String ta
addFunction(map, "math", new Cos("cosradians"));
addFunction(map, "math", new SinDegrees("sin"));
addFunction(map, "math", new Sin("sinradians"));
addFunction(map, "math", new Sign("sign"));
addFunction(map, "math", new Asin("asin"));
addFunction(map, "math", new Acos("acos"));
addFunction(map, "math", new Atan("atan"));
Expand Down

0 comments on commit 0781cab

Please sign in to comment.