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

Function execute_binary1

FluidNC/src/Expression.cpp:103–139  ·  view source on GitHub ↗

! \brief Executes the operations: /, MOD, ** (POW), *. \param lhs pointer to the left hand side operand and result. \param operation \ref ngc_binary_op_t enum value. \param rhs pointer to the right hand side operand. \returns #Error::Ok enum value if processed without error, appropriate \ref Error enum value if not. */

Source from the content-addressed store, hash-verified

101\returns #Error::Ok enum value if processed without error, appropriate \ref Error enum value if not.
102*/
103static Error execute_binary1(float& lhs, ngc_binary_op_t operation, const float& rhs) {
104 Error status = Error::Ok;
105
106 switch (operation) {
107 case Binary_DividedBy:
108 if (rhs == 0.0f || rhs == -0.0f)
109 status = Error::ExpressionDivideByZero; // Attempt to divide by zero
110 else
111 lhs = lhs / rhs;
112 break;
113
114 case Binary_Modulo: // always calculates a positive answer
115 lhs = fmodf(lhs, rhs);
116 if (lhs < 0.0f)
117 lhs = lhs + fabsf(rhs);
118 break;
119
120 case Binary_Power:
121 if (lhs < 0.0f && floorf(rhs) != rhs)
122 status = Error::ExpressionInvalidArgument; // Attempt to raise negative value to non-integer power
123 else
124 lhs = powf(lhs, rhs);
125 break;
126
127 case Binary_Times:
128 lhs = lhs * rhs;
129 break;
130
131 default:
132 status = Error::ExpressionUnknownOp;
133 }
134
135 if (status != Error::Ok)
136 report_param_error(status);
137
138 return status;
139}
140
141/*! \brief Executes the operations: +, -, AND, OR, XOR, EQ, NE, LT, LE, GT, GE
142The RS274/NGC manual does not say what

Callers 1

execute_binaryFunction · 0.85

Calls 1

report_param_errorFunction · 0.85

Tested by

no test coverage detected