Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.66k stars 874 forks source link

Potentially incorrect function `ceil_divide_signed` #2005

Open chungwong opened 6 months ago

chungwong commented 6 months ago

Application Version Versions including this commit https://github.com/Ultimaker/CuraEngine/commit/3b34b69277

It looks like this function is logically incorrect?

inline unsigned int ceil_divide_signed(int dividend, int divisor) //!< Return dividend divided by divisor rounded up towards positive infinity.
{
    return (dividend / divisor) + (dividend * divisor > 0 ? 1 : 0);
}

// it returns 31 instead of 30
ceil_divide_signed(90, 3);

Is this beahviour expected?