riksweeney / edgar

A 2D platform game with a persistent world. When Edgar's father fails to return home after venturing out one dark and stormy night, Edgar fears the worst: he has been captured by the evil sorcerer who lives in a fortress beyond the forbidden swamp.
https://www.parallelrealities.co.uk/games/edgar
116 stars 28 forks source link

Fix compiler warnings for abs() #62

Closed lumidify closed 1 year ago

lumidify commented 1 year ago

When compiling with clang, there are a lot of warnings warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] because abs is used with floating-point values in many places. This isn't really a problem since the values are just automatically casted to int before the function is called, but the warnings are annoying. There are two ways to fix them: One way is to just cast all the floats to int to make the warnings go away. The other way is to replace abs with fabsf. I used the latter option in this pull request, but I'm wondering if maybe the first way would be better. The problem is that it seems as if fabsf would be a better fit in most places, but using it does change the behavior very slightly since the values aren't rounded down anymore, so perhaps bugs could crop up somewhere. What's your opinion on this? If you want, I can just add a bunch of casts so the warnings go away, but the behavior isn't changed at all.