when I'm converting string '-0'
in float it returns float type -0
example
$x = '-0';
$y = (float)$x;
result => float -0
why -0
is float number ?
when I'm converting string '-0'
in float it returns float type -0
example
$x = '-0';
$y = (float)$x;
result => float -0
why -0
is float number ?
The IEEE 754 standard, which is how almost all computer languages implement floating point numbers, has both a +0
and a -0
value.
For most operations, +0
and -0
can be used interchangeably.
However, operations that error out to infinity, use +0
or -0
to go to +Infinity and -Infinity.
Because -0
is a valid floating point number, it makes perfect sense that casting -0
to a float would do exactly as you asked --- returning a floating point number with a value of exactly -0
.