Closed CrackedP0t closed 9 years ago
C has sign?
Only similar reference I could find was for math.h signbit
, which says "(if zero is unsigned, it is considered positive)" Which indicates to me that the lume implementation isn't so far off.
In anycase, I think that the behavior for 0 should be undefined as the sign of 0 is undefined.
Returning 0 for sign(0)
is really helpful for math and simplifying code. 0 being undefined might be more semantically correct, but returning 0 is more practically useful in my experience.
The current implementation was written such that its result can be multiplied with another value to set its sign, the behaviour of the function: considering zero an unsigned number such that the function always returns either -1
or 1
was intentional in this regard -- the outcome of multiplying being that the result is always the original value with only its sign changed. I've personally found this behaviour works well in practise.
Also note that the function mimics the behaviour of unity's sign() function, which feels like a good base line:
Return value is 1 when f is positive or zero, -1 when f is negative.
Without at least some more compelling reasons or actual examples I don't see the behaviour being changed. You may simply have to override the function with your desired behaviour in projects where you use lume.
In C
sign(0)
returns 0, and it makes more sense to me to have it that way.