有什么东西比PHP中的任何数字都大吗? [英] Is there something that's larger than any numbers in PHP?

查看:106
本文介绍了有什么东西比PHP中的任何数字都大吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在PHP中模拟一个∞.

I need to simulate a ∞ in PHP.

因此min(∞,$number)始终为$number.

推荐答案

我想对于整数,您可以使用

I suppose that, for integers, you could use PHP_INT_MAX , the following code :

var_dump(PHP_INT_MAX);

在我的机器上提供此输出:

Gives this output, on my machine :

int 2147483647


但是你必须小心;参见
整数溢出 (报价):


But you have to be careful ; see Integer overflow (quoting) :

如果PHP遇到的数字超出了 整数类型的边界,它将 被解释为浮点数. 另外,导致 超出界限的数字 整数类型将返回浮点数 代替.

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

然后,从浮点数文档页面:

And, from the Floating point numbers documentation page :

浮子的大小是 取决于平台,尽管最大 〜1.8e308的精度为 常见的是大约14个十进制数字 值(64位IEEE格式).

The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).

考虑到整数溢出,并且视您的情况而定,使用这种值可能是更好的(?)解决方案...

Considering the integer overflow, and depending on your case, using this kind of value might be a better (?) solution...

这篇关于有什么东西比PHP中的任何数字都大吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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