Math Round / Ceiling / Floor

Moderators: TomKerekes, dynomotion

Post Reply
suumas
Posts: 5
Joined: Sat Dec 05, 2020 4:51 pm

Math Round / Ceiling / Floor

Post by suumas » Sat Dec 05, 2020 5:17 pm

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.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Math Round / Ceiling / Floor

Post by TomKerekes » Sat Dec 05, 2020 5:38 pm

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)
Regards,

Tom Kerekes
Dynomotion, Inc.

suumas
Posts: 5
Joined: Sat Dec 05, 2020 4:51 pm

Re: Math Round / Ceiling / Floor

Post by suumas » Sat Dec 05, 2020 6:36 pm

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?

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Math Round / Ceiling / Floor

Post by TomKerekes » Sat Dec 05, 2020 8:28 pm

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.
Regards,

Tom Kerekes
Dynomotion, Inc.

suumas
Posts: 5
Joined: Sat Dec 05, 2020 4:51 pm

Re: Math Round / Ceiling / Floor

Post by suumas » Sat Dec 05, 2020 9:22 pm

Thanks again for a quick and complete answer!

Post Reply