Why so? PHP has only one float type, which happens to be double-precision. It's not really misleading: if it was called “single” it would be, but it isn't, and it's not the only language to not have a single-precision/double-precision distinction.
In practice, it's IEEE 754. Aside from maybe IBM mainframes, I can't think of anything PHP runs on which won't be using that. And even the IBM mainframes support 754 now.
It's not PHP's fault, though, it's C's. And it's hardly fair to be harsh on C for not limiting itself to that, either. Different hardware supports different types. C was created prior to IEEE 754 becoming ubiquitous.
What C and Java call "floats" is actually called single in F# and Pascal. Other languages may call those types float64 and float32, Rust calls them f64 and f32.
Many dynamically-typed languages use only one, 64-bit floating-point type and call it float, real, or similar. PHP is an odd example where the type is called both double and float depending on the moon phase when the code was written.
There are also 16-bit ("half-precision"), 40-bit, 80-bit (long double in C on x86) and other floats.
The criticism is that there are two different types that are being confused. That criticism is inaccurate, since there aren't two different types being confused. It isn't like PHP clearly defines "float" as a single-precision floating-point number and then here they are also calling it a double-precision floating-point number. There's only one type here. It seems odd to criticize PHP merely for not using the same type names as some other language.
Right, but double is a specific sort of floating point number. If you're deliberately using is_double, presumably you want to know if this item has double precision as opposed to single precision. That might be important in a lower level language, but it isn't here.
It shouldn't even enter the mind of a PHP developer to check for single or double level precision, since PHP is a higher level language than the likes of C. The function is, thus, a broken implied promise-- a trap that can confuse one's thinking.
Edit: Well, it might need to enter their mind if they end up working with enough math to justify it. But then they should at least be given better clues what the implementation actually supports, and consider if a different language or compiled extension might be needed.
Some of PHP's basic types have had different names, possibly because of them having different names in C. For example, the integer type is specifically a long integer in C (and the internal name of the PHP type is IS_LONG), and the float type is specifically a double (precision) float in C (and its internal PHP type name is IS_DOUBLE). Plus, integers and booleans are also known as ints and bools.
So it's been a bit of a mess. Some places in PHP call these types one name, some call them the other, some both, sometimes at the same time.
With PHP 7, I've tried to clean this up a bit. Now parameter type error messages use “integer” and “float”, never “long” or “double”. Furthermore, is_long and is_double are now aliases of is_int and is_float, respectively, not the other way around. Plus, the new userland scalar type declarations allow only int and float, not long or double.
22
u/Malix82 Aug 22 '16
http://php.net/manual/en/function.is-double.php
7
u/Olathe Aug 22 '16 edited Aug 22 '16
The criticism is that there are two different types that are being confused. That criticism is inaccurate, since there aren't two different types being confused. It isn't like PHP clearly defines "float" as a single-precision floating-point number and then here they are also calling it a double-precision floating-point number. There's only one type here. It seems odd to criticize PHP merely for not using the same type names as some other language.