php 中的浮点数范围.-0 是浮点数? [英] float number range in php. -0 is float?

查看:89
本文介绍了php 中的浮点数范围.-0 是浮点数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 float 中转换字符串 '-0' 时,它返回 float 类型 -0

when I'm converting string '-0'in float it returns float type -0

例子

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

结果 => 浮动 -0

result => float -0

为什么 -0 是浮点数?

推荐答案

IEEE 754 标准是几乎所有计算机语言实现浮点数的方式,同时具有 +0-0 值.

The IEEE 754 standard, which is how almost all computer languages implement floating point numbers, has both a +0 and a -0 value.

对于大多数操作,+0-0 可以互换使用.

For most operations, +0 and -0 can be used interchangeably.

但是,错误到无穷大的操作,使用 +0-0 转到 +Infinity 和 -Infinity.

However, operations that error out to infinity, use +0 or -0 to go to +Infinity and -Infinity.

因为 -0 是一个有效的浮点数,所以将 -0 转换为浮点数完全符合您的要求 --- 返回一个浮点数点数,其值恰好为 -0.

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.

这篇关于php 中的浮点数范围.-0 是浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆