Page 1 of 1
Math Round / Ceiling / Floor
Posted: Sat Dec 05, 2020 5:17 pm
by suumas
Is there a way to round up/down/off floating point numbers into an integer or some specific level of precision within G code? E.g. #1 = [ceil[0.875 / 0.25]]
I ultimately want to control a loop and while I could manage with an iterator and conditional check, it would be much simpler and more useful everywhere to do the math in advance. I'm using v4.34, btw.
Re: Math Round / Ceiling / Floor
Posted: Sat Dec 05, 2020 5:38 pm
by TomKerekes
Hi suumas,
FUP, FIX, and ROUND are supported
Code: Select all
#1 = FUP[1.02] (ceil result 2)
#2 = FIX[1.02] (floor result 1)
#3 = ROUND[1.5] (round up/down result 2)
Re: Math Round / Ceiling / Floor
Posted: Sat Dec 05, 2020 6:36 pm
by suumas
Thanks for the prompt reply!!
I'm searching through the help but I can't find those functions. Where can I find a complete list of all such functions?
Re: Math Round / Ceiling / Floor
Posted: Sat Dec 05, 2020 8:28 pm
by TomKerekes
Hi suumas,
The GCode Interpreter is based on the public domain NIST RS274NGC Interpreter you can download a manual
here. Section 3.3.2.3 describes expressions.
Or you can look at the source code
See execute_unary() in \GCodeInterpreter\rs274ngc.cpp also add your own.
Re: Math Round / Ceiling / Floor
Posted: Sat Dec 05, 2020 9:22 pm
by suumas
Thanks again for a quick and complete answer!