gpt4 book ai didi

php - PHP中是否有类似NEGATIVE_INFINITY的东西?

转载 作者:可可西里 更新时间:2023-10-31 22:11:16 25 4
gpt4 key购买 nike

我喜欢 javascript 中的负无穷大值,我认为在很多情况下使用它是有用且干净的,但在 PHP 中找不到类似的东西,它存在吗?

最佳答案

-INF 

PHP Documentation 的评论中得到它:

I just learnt of INF today and found out that it can be used in comparisons:

echo 5000 < INF ? 'yes' : 'no';       // outputs 'yes'
echo INF < INF ? 'yes' : 'no'; // outputs 'no'
echo INF <= INF ? 'yes' : 'no'; // outputs 'yes'
echo INF == INF ? 'yes' : 'no'; // outputs 'yes'

You can also take its negative:

echo -INF < -5000 ? 'yes' : 'no';    // outputs 'yes'

Division by INF is allowed:

echo 1/INF;    // outputs '0'

And test for it:

is_infinite(INF);   returns true
is_infinite(-INF); returns true
is_infinite(1.01); return false

关于php - PHP中是否有类似NEGATIVE_INFINITY的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34771128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com