Skip to content

Commit

Permalink
Allow one non-double in equals_epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Apr 29, 2024
1 parent c67c16f commit 9bd7984
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/main/java/com/laytonsmith/core/functions/BasicLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2706,8 +2706,8 @@ public Boolean runAsync() {

@Override
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
double d1 = ArgumentValidation.getDouble(args[0], t);
double d2 = ArgumentValidation.getDouble(args[1], t);
double d1 = ArgumentValidation.getNumber(args[0], t);
double d2 = ArgumentValidation.getNumber(args[1], t);
double epsilon = ArgumentValidation.getDouble(args[2], t);
return CBoolean.get(java.lang.Math.abs(d1 - d2) < epsilon);
}
Expand All @@ -2724,7 +2724,7 @@ public Integer[] numArgs() {

@Override
public String docs() {
return "boolean {double d1, double d2, double epsilon}"
return "boolean {double d1, number d2, double epsilon | number d1, double d2, double epsilon}"
+ " When comparing the equality of floating point numbers, it is often impossible to directly"
+ " compare via == (equals) since two floating point numbers that might be actually semantically"
+ " equivalent, are represented slightly differently in the computer, thus making them not actually"
Expand All @@ -2742,10 +2742,16 @@ public Version since() {
@Override
public FunctionSignatures getSignatures() {
return new SignatureBuilder(CBoolean.TYPE)
.param(CDouble.TYPE, "d1", "The first double to compare.")
.param(CNumber.TYPE, "d1", "The first number to compare.")
.param(CDouble.TYPE, "d2", "The second double to compare.")
.param(CDouble.TYPE, "epsilon",
"The degree of difference to use to determine equality, for instance 0.00001")
.newSignature(CBoolean.TYPE)
.param(CDouble.TYPE, "d1", "The first double to compare.")
.param(CNumber.TYPE, "d2", "The second number to compare.")
.param(CDouble.TYPE, "epsilon",
"The degree of difference to use to determine equality, for instance 0.00001")

.build();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/samp_main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
@server_name = '<Server Name>';

# Echo out a server greeting to the console
console('Welcome to this server, which is running CommandHelper! (Change this message in plugins/CommandHelper/main.ms)');
console('CommandHelper successfully installed! To get started, visit https://methodscript.com, and visit the learning'
. ' trail at the bottom, and particularly the Beginner's and Advanced Guides.'
. ' (Change this message in plugins/CommandHelper/main.ms)');

# Bind an event to the player join, and tell ops hello.
# We send in @server_name, so we can use it inside the event handler
Expand Down

0 comments on commit 9bd7984

Please sign in to comment.