C ++: store large numbers in a float, like PHP?

In PHP, if you go above INT_MAX, it will use it as a float, allowing you to generate very large numbers (also non-decimal), is it possible to do this in C ++, or how do they store floating point / double precision numbers?

The reason I want to compare large factorials, but something seems 80!too big for an unsigned integer.

+3
source share
5 answers

The language will not make a switch for you, but it has data types floatand double, which are usually 32-bit and 64-bit IEEE floats, respectively.

64- 80!, , . , : , GMP.

+2

bigint, . float-int PHPs

-

class IntFloat {
   union {
      float fval;
      int ival;
    } val;
    bool foatUsed;

    public:
      setVal(float val)
      {
        this->val.fval = val;
        floatUsed = true;
      }

      setVal(int val)
      {
        this->val.ival = val;
        floatUsed = false;
      }

       //additional code for getters, setters, operators etc
 }

, PHP, .

int- wikipedia

PS:

" / ?"

, . ++ , PHP ( -, PHP-). , PHP .

+1

GMP Big Integer, ++. . .

+1

++ " ", , , int float (a double , IIRC 170!) , .

, fp, , , , . , fp- , ( , , ).

, bigint; Google.

+1

__float128 ( ), , .

0

Source: https://habr.com/ru/post/1766624/


All Articles