Is there something that's larger than any numbers in PHP?

前端 未结 9 1531
谎友^
谎友^ 2021-01-19 03:12

I need to simulate a ∞ in PHP.

So that min(∞,$number) is always $number.

相关标签:
9条回答
  • 2021-01-19 03:59

    min($number, $number + 1) ??

    0 讨论(0)
  • 2021-01-19 04:00

    In Perl you can use

    $INF = 9**9E9;
    

    which is larger than any value you can store in IEEE floating point numbers. And that really works as intended: any non-infinite number will be smaller than $INF:

    $N < $INF
    

    is true for any "normal" number $N.

    Maybe you use it in PHP too?

    0 讨论(0)
  • 2021-01-19 04:00

    If your only concern is comparison function then yes, you can use array(), it will be always larger then any number

    like

    echo min(array(), 9999999999999999);
    

    or

    if (array() > 9999999999999999) {
      echo 'array won';
    } else {
      echo 'number won';
    }
    
    0 讨论(0)
提交回复
热议问题