prusa3d / PrusaSlicer

G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)
https://www.prusa3d.com/prusaslicer/
GNU Affero General Public License v3.0
7.78k stars 1.94k forks source link

Floating point arithmetic division does not work in custom g-code macro #13504

Open Kekht opened 1 month ago

Kekht commented 1 month ago

Description of the bug

Somehow weirdly PrusaSlicer does not do floating point arithmetic division, casting every part of any expression to lesser integer. This is weird behaviour, because Prusa Knowledge Base mentions such functions as int(), round() and digits(), wich supposed to work with floating point. Also current behaviour makes meaningless mentioning of those functions at Prusa Knowledge Base and forces to use some crutches to get proper value.

Project file & How to reproduce

In any g-code macro field:

{local test = 5/10}
; 5/10 = {test}

will produce ; 5/10 = 0

Checklist of files included above

Version of PrusaSlicer

2.8.1-win64

Operating system

Windows 10

Printer model

any

Kekht commented 1 month ago

It seems that solution is to use .0 for such cases in any operand, e.g.:

{local test = 5/10.0}
; 5/10 = {test}

Now gives: ; 5/10 = 0.5

That is still obvious and should be updated at Knowledge Base. For example there are arithmetic operations exaple shows: M104 S{first_layer_temperature[0] * 2/3} if that 2/3 operand somehow pre-calculated, and expressed as (2/3):

{local tempPart = 2/3}
...
M104 S{first_layer_temperature[0] * 2/3}

then we will get M104 S0