Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/src/gcode/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,10 @@ false, and any non-zero number is equivalent to logical true.

== Equality and floating-point values

The RS274/NGC language only supports floating-point values of finite
precision. Therefore, testing for equality or inequality of two
floating-point values is inherently problematic. The interpreter
solves this problem by considering values equal if their absolute
difference is less than 0.0001 (this value is defined as
Testing for equality or inequality of two
double-precision floating-point values is inherently problematic.
The interpreter solves this problem by considering values equal if
their absolute difference is less than 1e-6 (this value is defined as
'TOLERANCE_EQUAL' in src/emc/rs274ngc/interp_internal.hh).

[[gcode:functions]]
Expand Down
12 changes: 6 additions & 6 deletions src/emc/rs274ngc/interp_execute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ int Interp::execute_binary2(double *left, //!< pointer to the left operan
*left = (*left < *right) ? 1.0 : 0.0;
break;
case EQ:
diff = *left - *right;
diff = (diff < 0) ? -diff : diff;
diff = fabs(*left - *right);
*left = (diff < TOLERANCE_EQUAL) ? 1.0 : 0.0;
break;
case NE:
diff = *left - *right;
diff = (diff < 0) ? -diff : diff;
diff = fabs(*left - *right);
*left = (diff >= TOLERANCE_EQUAL) ? 1.0 : 0.0;
break;
case LE:
*left = (*left <= *right) ? 1.0 : 0.0;
diff = fabs(*left - *right);
*left = ((diff < TOLERANCE_EQUAL) || (*left <= *right)) ? 1.0 : 0.0;
break;
case GE:
*left = (*left >= *right) ? 1.0 : 0.0;
diff = fabs(*left - *right);
*left = ((diff < TOLERANCE_EQUAL) || (*left >= *right)) ? 1.0 : 0.0;
break;
case GT:
*left = (*left > *right) ? 1.0 : 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/emc/rs274ngc/interp_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ Tighter tolerance down to a minimum of 1 micron +- also accepted.
#define SPIRAL_RELATIVE_TOLERANCE 0.001

/* angle threshold for concavity for cutter compensation, in radians */
#define TOLERANCE_CONCAVE_CORNER 0.05
#define TOLERANCE_EQUAL 0.0001 /* two numbers compare EQ if the
#define TOLERANCE_CONCAVE_CORNER 0.05
#define TOLERANCE_EQUAL 1e-6 /* two numbers compare EQ if the
difference is less than this */

static inline bool equal(double a, double b)
Expand Down