在PHP中的最大浮点值 [英] Maximum float value in php

查看:95
本文介绍了在PHP中的最大浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式检索PHP的最大浮动值。类似于 FLT_MAX std :: numeric_limits<在C / C ++中使用float> :: max()

我使用类似下面的代码:

  $ minimumCost = MAXIMUM_FLOAT_VALUE ??; 

foreach($ object as $ object)
{
$ cost = $ object-> CalculateCost();
if($ cost <$ minimumCost)
{
$ minimumCost = $ cost;




$ b

(使用php 5.2)

解决方案

浮点数最大值是依赖于平台的,虽然它可能有用,但似乎没有(简单)的方法来获取它。但是你可以使用 INF (infinite)常量,如果目标只有一个巨大的数值占位符值。


Is there a way to programmatically retrieve the maximum float value for php. Akin to FLT_MAX or std::numeric_limits< float >::max() in C / C++?

I am using something like the following:

$minimumCost = MAXIMUM_FLOAT_VALUE??;

foreach ( $objects as $object )
{
    $cost = $object->CalculateCost();
    if ( $cost < $minimumCost )
    {
        $minimumCost = $cost;
    }
}

(using php 5.2)

解决方案

The float maximum is platform-dependant, and even though it could be useful to get it, there seems to be no (simple) way to get it. You can however use the INF (infinite) constant, which will be bigger than any other value you can ever put in a numeric type, if the goal is only to have a huge placeholder value.

这篇关于在PHP中的最大浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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