float number range in php. -0 is float?

扶醉桌前 提交于 2019-12-04 02:40:03

问题


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 ?


回答1:


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.




回答2:


We all know that all integers are floats. And in PHP from here

Integers can be specified in decimal (base 10), hexadecimal (base 16), octal (base 8) or binary (base 2) notation, optionally preceded by a sign (- or +)

So -0 is an int which is normally a float



来源:https://stackoverflow.com/questions/25259274/float-number-range-in-php-0-is-float

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!