开发者

Maximum float value in php

开发者 https://www.devze.com 2022-12-26 20:28 出处:网络
Is there a way to programmatically retrieve the maximum flo开发者_运维百科at value for php.Akin to FLT_MAX or std::numeric_limits< float >::max() in C / C++?

Is there a way to programmatically retrieve the maximum flo开发者_运维百科at 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.


You can use the PHP_FLOAT_MAX predefined constant, I believe.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号