Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
made min and max better
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRTTV committed Nov 12, 2023
1 parent 037aeac commit 66ce138
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/ca/rttv/chatcalc/MathematicalFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,25 @@ public MathematicalFunction(String value) {
public double apply(double... values) {
if (functions.containsKey(func)) {
if (func.equals("min")) {
if (values.length != 2) {
if (values.length == 0) {
throw new IllegalArgumentException();
}
return Math.min(values[0], values[1]);
double min = values[0];
for (double value : values) {
min = Math.min(min, value);
}
return min;
}

if (func.equals("max")) {
if (values.length != 2) {
if (values.length == 0) {
throw new IllegalArgumentException();
}
return Math.max(values[0], values[1]);
double max = values[0];
for (double value : values) {
max = Math.max(max, value);
}
return max;
}

if (func.equals("clamp")) {
Expand Down

0 comments on commit 66ce138

Please sign in to comment.