Skip to content

Efficient Round Function

Godlike Productions edited this page Jan 7, 2022 · 1 revision

This takes advantage of the limits of the double precision numbers. It does rounding with only Addition, which is computationally efficient.

function round(num)
    return num + (2^52 + 2^51) - (2^52 + 2^51)
end