factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
61 stars 15 forks source link

Issue with math.clamp and -0 #43

Closed blargh2015 closed 2 years ago

blargh2015 commented 2 years ago

While mathematically, it's true the -0 == 0 (and Lua agrees with that), this is probably not expected behavior:

game.print("clamp of -0 is "..math.clamp(-0, 0, 100))

Results in: clamp of -0 is -0

The desired output here would have been clamp of -0 is 0

On the fence if this is a "bug" per se, but if people are using clamp (and in my case, using as a percentage), displaying "-0%" is a little ugly and slightly unexpected.