Skip to content

Commit

Permalink
added mod and modF
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Sep 17, 2024
1 parent a3e221c commit 7844cd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ private static Map<String, Value> createMembers() {
}

}));
componentMembers.put("mod", new FunctionValue.ExternalFunctionValue(args -> {

if (args.size() == 2 && args.get(0).deref().isNumeric() && args.get(1).deref().isNumeric()) {
NumericValue a = (NumericValue) args.get(0).deref();
NumericValue b = (NumericValue) args.get(1).deref();
return NumericValue.valueOf(a.doubleValue() % b.doubleValue());
}

throw new InterpreterException("Wrong arguments for mod:" + args);
}));
componentMembers.put("modF", new FunctionValue.ExternalFunctionValue(args -> {

if (args.size() == 2 && args.get(0).deref().isNumeric() && args.get(1).deref().isNumeric()) {
NumericValue a = (NumericValue) args.get(0).deref();
NumericValue b = (NumericValue) args.get(1).deref();
return NumericValue.valueOf(a.floatValue() % b.floatValue());
}

throw new InterpreterException("Wrong arguments for mod:" + args);
}));
componentMembers.put("minRealFromArray", new FunctionValue.ExternalFunctionValue(args -> {

if (args.get(0).deref() instanceof ArrayValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ module Math {
bool isClose(real a, real b, real absoluteTolerance, real relativeTolerance);
real min(real a, real b);
real minRealFromArray(real realArray[]);
real mod(real a, real b);
real modF(float a, float b);
}

0 comments on commit 7844cd1

Please sign in to comment.