简体   繁体   English

浮点数范围在php中。 -0是浮点数?

[英]float number range in php. -0 is float?

when I'm converting string '-0' in float it returns float type -0 当我在float中转换字符串'-0' ,它返回float类型-0

example

$x = '-0';
$y = (float)$x;

result => float -0 结果=>浮点-0

why -0 is float number ? 为什么-0是浮点数?

The IEEE 754 standard, which is how almost all computer languages implement floating point numbers, has both a +0 and a -0 value. IEEE 754标准(几乎所有计算机语言都实现浮点数)是同时具有+0-0值。

For most operations, +0 and -0 can be used interchangeably. 对于大多数操作, +0-0可以互换使用。

However, operations that error out to infinity, use +0 or -0 to go to +Infinity and -Infinity. 但是,错误出无穷大的运算,请使用+0-0转到+ Infinity和-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 . 由于-0是有效的浮点数,因此将-0强制转换为浮点数将完全按照您的要求做是很有意义的-返回一个值为-0的浮点数。

We all know that all integers are floats. 我们都知道所有整数都是浮点数。 And in PHP from here 而在PHP从这里

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 +) 整数可以十进制(以10为底),十六进制(以16为底),八进制(以8为底)或二进制(以2为底)表示法指定,还可以在符号前加一个符号(-或+)

So -0 is an int which is normally a float 所以-0是一个int ,通常是一个float

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM