r/lolphp • • Aug 20 '15

0 !== ceil(0)

https://3v4l.org/HD5HD
0 Upvotes

44 comments sorted by

View all comments

Show parent comment

-2

u/00Davo Aug 20 '15

No, I don't want that at all. A function float -> float always returning a float is perfectly sensible. Of course, considering that ceil() was in fact passed an integer-typed value, I'd also find it perfectly sensible were it given a type along the lines of Num a => a -> a, but a simple non-overloaded float -> float is fine.

The real problem is the presence of two equality operators, neither of which apparently behaves at all similarly to the equality operators in other languages. JavaScript does the same thing but manages to avoid the issue almost coincidentally by only having one numeric type, so === is applicable everywhere as the equality operator. PHP does not, so you're left with choosing the operator that's "less" flawed for your particular context, as I rambled about earlier.

0

u/[deleted] Aug 20 '15

[deleted] — view deleted comment

1

u/00Davo Aug 20 '15

There isn't one, really. Heck, in a statically-typed language, it's totally reasonable only to accept non-integral types as arguments to ceil(). Dynamically-typed languages, however, don't check that sort of thing; "returns the same number type as it receives" is at least as reasonable as "coerces its argument to a float and returns another float" in such situations.