MCPcopy Create free account
hub / github.com/bdring/FluidNC / execute_binary2

Function execute_binary2

FluidNC/src/Expression.cpp:152–207  ·  view source on GitHub ↗

! \brief Executes the operations: +, -, AND, OR, XOR, EQ, NE, LT, LE, GT, GE The RS274/NGC manual does not say what the calculated value of the logical operations should be. This function calculates either 1.0 (meaning true) or 0.0 (meaning false). Any non-zero input value is taken as meaning true, and only 0.0 means false. \param lhs pointer to the left hand side operand and result. \param opera

Source from the content-addressed store, hash-verified

150\returns #Error::Ok enum value if processed without error, appropriate \ref Error enum value if not.
151*/
152static Error execute_binary2(float& lhs, ngc_binary_op_t operation, const float& rhs) {
153 switch (operation) {
154 case Binary_And2:
155 lhs = ((lhs == 0.0f) || (rhs == 0.0f)) ? 0.0f : 1.0f;
156 break;
157
158 case Binary_ExclusiveOR:
159 lhs = (((lhs == 0.0f) && (rhs != 0.0f)) || ((lhs != 0.0f) && (rhs == 0.0f))) ? 1.0f : 0.0f;
160 break;
161
162 case Binary_Minus:
163 lhs = (lhs - rhs);
164 break;
165
166 case Binary_NotExclusiveOR:
167 lhs = ((lhs != 0.0f) || (rhs != 0.0f)) ? 1.0f : 0.0f;
168 break;
169
170 case Binary_Plus:
171 lhs = (lhs + rhs);
172 break;
173
174 case Binary_LT:
175 lhs = (lhs < rhs) ? 1.0f : 0.0f;
176 break;
177
178 case Binary_EQ: {
179 float diff = lhs - rhs;
180 diff = (diff < 0.0f) ? -diff : diff;
181 lhs = (diff < TOLERANCE_EQUAL) ? 1.0f : 0.0f;
182 } break;
183
184 case Binary_NE: {
185 float diff = lhs - rhs;
186 diff = (diff < 0.0f) ? -diff : diff;
187 lhs = (diff >= TOLERANCE_EQUAL) ? 1.0f : 0.0f;
188 } break;
189
190 case Binary_LE:
191 lhs = (lhs <= rhs) ? 1.0f : 0.0f;
192 break;
193
194 case Binary_GE:
195 lhs = (lhs >= rhs) ? 1.0f : 0.0f;
196 break;
197
198 case Binary_GT:
199 lhs = (lhs > rhs) ? 1.0f : 0.0f;
200 break;
201
202 default:
203 return Error::ExpressionUnknownOp;
204 }
205
206 return Error::Ok;
207}
208
209/*! \brief Executes a binary operation.

Callers 1

execute_binaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected