{
    "content": [
        {
            "type": "text",
            "text": "# bignum (info)\n\n## NAME\n\nbignum - Transparent BigNumber support for Perl\n\n## SYNOPSIS\n\nuse bignum;\n$x = 2 + 4.5,\"\\n\";                    # BigFloat 6.5\nprint 2  512 * 0.1,\"\\n\";            # really is what you think it is\nprint inf * inf,\"\\n\";                 # prints inf\nprint NaN * 3,\"\\n\";                   # prints NaN\n{\nno bignum;\nprint 2  256,\"\\n\";                # a normal Perl scalar now\n}\n# for older Perls, import into current package:\nuse bignum qw/hex oct/;\nprint hex(\"0x1234567890123490\"),\"\\n\";\nprint oct(\"01234567890123490\"),\"\\n\";\n\n## DESCRIPTION\n\nAll operators (including basic math operations) are overloaded. Integer\nand floating-point constants are created as proper BigInts or\nBigFloats, respectively.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **CAVEATS**\n- **MODULES USED**\n- **EXAMPLES**\n- **BUGS**\n- **SUPPORT**\n- **LICENSE**\n- **SEE ALSO**\n- **AUTHORS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "bignum",
        "section": "",
        "mode": "info",
        "summary": "bignum - Transparent BigNumber support for Perl",
        "synopsis": "use bignum;\n$x = 2 + 4.5,\"\\n\";                    # BigFloat 6.5\nprint 2  512 * 0.1,\"\\n\";            # really is what you think it is\nprint inf * inf,\"\\n\";                 # prints inf\nprint NaN * 3,\"\\n\";                   # prints NaN\n{\nno bignum;\nprint 2  256,\"\\n\";                # a normal Perl scalar now\n}\n# for older Perls, import into current package:\nuse bignum qw/hex oct/;\nprint hex(\"0x1234567890123490\"),\"\\n\";\nprint oct(\"01234567890123490\"),\"\\n\";",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "Some cool command line examples to impress the Python crowd ;)",
            "perl -Mbignum -le 'print sqrt(33)'",
            "perl -Mbignum -le 'print 2*255'",
            "perl -Mbignum -le 'print 4.5+2*255'",
            "perl -Mbignum -le 'print 3/7 + 5/7 + 8/3'",
            "perl -Mbignum -le 'print 123->isodd()'",
            "perl -Mbignum -le 'print log(2)'",
            "perl -Mbignum -le 'print exp(1)'",
            "perl -Mbignum -le 'print 2  0.5'",
            "perl -Mbignum=a,65 -le 'print 2  0.2'",
            "perl -Mbignum=a,65,l,GMP -le 'print 7  7777'"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 315,
                "subsections": []
            },
            {
                "name": "CAVEATS",
                "lines": 48,
                "subsections": []
            },
            {
                "name": "MODULES USED",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "bignum - Transparent BigNumber support for Perl\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use bignum;\n\n$x = 2 + 4.5,\"\\n\";                    # BigFloat 6.5\nprint 2  512 * 0.1,\"\\n\";            # really is what you think it is\nprint inf * inf,\"\\n\";                 # prints inf\nprint NaN * 3,\"\\n\";                   # prints NaN\n\n{\nno bignum;\nprint 2  256,\"\\n\";                # a normal Perl scalar now\n}\n\n# for older Perls, import into current package:\nuse bignum qw/hex oct/;\nprint hex(\"0x1234567890123490\"),\"\\n\";\nprint oct(\"01234567890123490\"),\"\\n\";\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "All operators (including basic math operations) are overloaded. Integer\nand floating-point constants are created as proper BigInts or\nBigFloats, respectively.\n\nIf you do\n\nuse bignum;\n\nat the top of your script, Math::BigFloat and Math::BigInt will be\nloaded and any constant number will be converted to an object\n(Math::BigFloat for floats like 3.1415 and Math::BigInt for integers\nlike 1234).\n\nSo, the following line:\n\n$x = 1234;\n\ncreates actually a Math::BigInt and stores a reference to in $x.  This\nhappens transparently and behind your back, so to speak.\n\nYou can see this with the following:\n\nperl -Mbignum -le 'print ref(1234)'\n\nDon't worry if it says Math::BigInt::Lite, bignum and friends will use\nLite if it is installed since it is faster for some operations. It will\nbe automatically upgraded to BigInt whenever necessary:\n\nperl -Mbignum -le 'print ref(2255)'\n\nThis also means it is a bad idea to check for some specific package,\nsince the actual contents of $x might be something unexpected. Due to\nthe transparent way of bignum \"ref()\" should not be necessary, anyway.\n\nSince Math::BigInt and BigFloat also overload the normal math\noperations, the following line will still work:\n\nperl -Mbignum -le 'print ref(1234+1234)'\n\nSince numbers are actually objects, you can call all the usual methods\nfrom BigInt/BigFloat on them. This even works to some extent on\nexpressions:\n\nperl -Mbignum -le '$x = 1234; print $x->bdec()'\nperl -Mbignum -le 'print 1234->copy()->binc();'\nperl -Mbignum -le 'print 1234->copy()->binc->badd(6);'\nperl -Mbignum -le 'print +(1234)->copy()->binc()'\n\n(Note that print doesn't do what you expect if the expression starts\nwith '(' hence the \"+\")\n\nYou can even chain the operations together as usual:\n\nperl -Mbignum -le 'print 1234->copy()->binc->badd(6);'\n1241\n\nUnder bignum (or bigint or bigrat), Perl will \"upgrade\" the numbers\nappropriately. This means that:\n\nperl -Mbignum -le 'print 1234+4.5'\n1238.5\n\nwill work correctly. These mixed cases don't do always work when using\nMath::BigInt or Math::BigFloat alone, or at least not in the way normal\nPerl scalars work.\n\nIf you do want to work with large integers like under \"use integer;\",\ntry \"use bigint;\":\n\nperl -Mbigint -le 'print 1234.5+4.5'\n1238\n\nThere is also \"use bigrat;\" which gives you big rationals:\n\nperl -Mbigrat -le 'print 1234+4.1'\n12381/10\n\nThe entire upgrading/downgrading is still experimental and might not\nwork as you expect or may even have bugs. You might get errors like\nthis:\n\nCan't use an undefined value as an ARRAY reference at\n/usr/local/lib/perl5/5.8.0/Math/BigInt/Calc.pm line 864\n\nThis means somewhere a routine got a BigFloat/Lite but expected a\nBigInt (or vice versa) and the upgrade/downgrad path was missing. This\nis a bug, please report it so that we can fix it.\n\nYou might consider using just Math::BigInt or Math::BigFloat, since\nthey allow you finer control over what get's done in which\nmodule/space. For instance, simple loop counters will be Math::BigInts\nunder \"use bignum;\" and this is slower than keeping them as Perl\nscalars:\n\nperl -Mbignum -le 'for ($i = 0; $i < 10; $i++) { print ref($i); }'\n\nPlease note the following does not work as expected (prints nothing),\nsince overloading of '..' is not yet possible in Perl (as of v5.8.0):\n\nperl -Mbignum -le 'for (1..2) { print ref($); }'\n\nOptions\nbignum recognizes some options that can be passed while loading it via\nuse.  The options can (currently) be either a single letter form, or\nthe long form.  The following options exist:\n\na or accuracy\nThis sets the accuracy for all math operations. The argument must be\ngreater than or equal to zero. See Math::BigInt's bround() function\nfor details.\n\nperl -Mbignum=a,50 -le 'print sqrt(20)'\n\nNote that setting precision and accuracy at the same time is not\npossible.\n\np or precision\nThis sets the precision for all math operations. The argument can be\nany integer. Negative values mean a fixed number of digits after the\ndot, while a positive value rounds to this digit left from the dot. 0\nor 1 mean round to integer. See Math::BigInt's bfround() function for\ndetails.\n\nperl -Mbignum=p,-50 -le 'print sqrt(20)'\n\nNote that setting precision and accuracy at the same time is not\npossible.\n\nt or trace\nThis enables a trace mode and is primarily for debugging bignum or\nMath::BigInt/Math::BigFloat.\n\nl or lib\nLoad a different math lib, see \"Math Library\".\n\nperl -Mbignum=l,GMP -e 'print 2  512'\n\nCurrently there is no way to specify more than one library on the\ncommand line. This means the following does not work:\n\nperl -Mbignum=l,GMP,Pari -e 'print 2  512'\n\nThis will be hopefully fixed soon ;)\n\nhex\nOverride the built-in hex() method with a version that can handle big\nnumbers. This overrides it by exporting it to the current package.\nUnder Perl v5.10.0 and higher, this is not so necessary, as hex() is\nlexically overridden in the current scope whenever the bignum pragma\nis active.\n\noct\nOverride the built-in oct() method with a version that can handle big\nnumbers. This overrides it by exporting it to the current package.\nUnder Perl v5.10.0 and higher, this is not so necessary, as oct() is\nlexically overridden in the current scope whenever the bigint pragma\nis active.\n\nv or version\nThis prints out the name and version of all modules used and then\nexits.\n\nperl -Mbignum=v\n\nMethods\nBeside import() and AUTOLOAD() there are only a few other methods.\n\nSince all numbers are now objects, you can use all functions that are\npart of the BigInt or BigFloat API. It is wise to use only the bxxx()\nnotation, and not the fxxx() notation, though. This makes it possible\nthat the underlying object might morph into a different class than\nBigFloat.\n\nCaveats\nBut a warning is in order. When using the following to make a copy of a\nnumber, only a shallow copy will be made.\n\n$x = 9; $y = $x;\n$x = $y = 7;\n\nIf you want to make a real copy, use the following:\n\n$y = $x->copy();\n\nUsing the copy or the original with overloaded math is okay, e.g. the\nfollowing work:\n\n$x = 9; $y = $x;\nprint $x + 1, \" \", $y,\"\\n\";     # prints 10 9\n\nbut calling any method that modifies the number directly will result in\nboth the original and the copy being destroyed:\n\n$x = 9; $y = $x;\nprint $x->badd(1), \" \", $y,\"\\n\";        # prints 10 10\n\n$x = 9; $y = $x;\nprint $x->binc(1), \" \", $y,\"\\n\";        # prints 10 10\n\n$x = 9; $y = $x;\nprint $x->bmul(2), \" \", $y,\"\\n\";        # prints 18 18\n\nUsing methods that do not modify, but test the contents works:\n\n$x = 9; $y = $x;\n$z = 9 if $x->iszero();                # works fine\n\nSee the documentation about the copy constructor and \"=\" in overload,\nas well as the documentation in BigInt for further details.\n\ninf()\nA shortcut to return Math::BigInt->binf(). Useful because Perl does\nnot always handle bareword \"inf\" properly.\n\nNaN()\nA shortcut to return Math::BigInt->bnan(). Useful because Perl does\nnot always handle bareword \"NaN\" properly.\n\ne\n# perl -Mbignum=e -wle 'print e'\n\nReturns Euler's number \"e\", aka exp(1).\n\nPI()\n# perl -Mbignum=PI -wle 'print PI'\n\nReturns PI.\n\nbexp()\nbexp($power,$accuracy);\n\nReturns Euler's number \"e\" raised to the appropriate power, to the\nwanted accuracy.\n\nExample:\n\n# perl -Mbignum=bexp -wle 'print bexp(1,80)'\n\nbpi()\nbpi($accuracy);\n\nReturns PI to the wanted accuracy.\n\nExample:\n\n# perl -Mbignum=bpi -wle 'print bpi(80)'\n\nupgrade()\nReturn the class that numbers are upgraded to, is in fact returning\n$Math::BigInt::upgrade.\n\nineffect()\nuse bignum;\n\nprint \"in effect\\n\" if bignum::ineffect;       # true\n{\nno bignum;\nprint \"in effect\\n\" if bignum::ineffect;     # false\n}\n\nReturns true or false if \"bignum\" is in effect in the current scope.\n\nThis method only works on Perl v5.9.4 or later.\n\nMath Library\nMath with the numbers is done (by default) by a module called\nMath::BigInt::Calc. This is equivalent to saying:\n\nuse bignum lib => 'Calc';\n\nYou can change this by using:\n\nuse bignum lib => 'GMP';\n\nThe following would first try to find Math::BigInt::Foo, then\nMath::BigInt::Bar, and when this also fails, revert to\nMath::BigInt::Calc:\n\nuse bignum lib => 'Foo,Math::BigInt::Bar';\n\nPlease see respective module documentation for further details.\n\nUsing \"lib\" warns if none of the specified libraries can be found and\nMath::BigInt did fall back to one of the default libraries.  To\nsuppress this warning, use \"try\" instead:\n\nuse bignum try => 'GMP';\n\nIf you want the code to die instead of falling back, use \"only\"\ninstead:\n\nuse bignum only => 'GMP';\n\nINTERNAL FORMAT\nThe numbers are stored as objects, and their internals might change at\nanytime, especially between math operations. The objects also might\nbelong to different classes, like Math::BigInt, or Math::BigFloat.\nMixing them together, even with normal scalars is not extraordinary,\nbut normal and expected.\n\nYou should not depend on the internal format, all accesses must go\nthrough accessor methods. E.g. looking at $x->{sign} is not a bright\nidea since there is no guaranty that the object in question has such a\nhashkey, nor is a hash underneath at all.\n\nSIGN\nThe sign is either '+', '-', 'NaN', '+inf' or '-inf' and stored\nseparately.  You can access it with the sign() method.\n\nA sign of 'NaN' is used to represent the result when input arguments\nare not numbers or as a result of 0/0. '+inf' and '-inf' represent plus\nrespectively minus infinity. You will get '+inf' when dividing a\npositive number by 0, and '-inf' when dividing any negative number by\n0.\n",
                "subsections": []
            },
            "CAVEATS": {
                "content": "Operator vs literal overloading\n\"bignum\" works by overloading handling of integer and floating point\nliterals, converting them to Math::BigInt or Math::BigFloat objects.\n\nThis means that arithmetic involving only string values or string\nliterals will be performed using Perl's built-in operators.\n\nFor example:\n\nuse bignum;\nmy $x = \"900000000000000009\";\nmy $y = \"900000000000000007\";\nprint $x - $y;\n\nwill output 0 on default 32-bit builds, since \"bigrat\" never sees the\nstring literals.  To ensure the expression is all treated as\n\"Math::BigInt\" or \"BigFloat\" objects, use a literal number in the\nexpression:\n\nprint +(0+$x) - $y;\n\nineffect()\nThis method only works on Perl v5.9.4 or later.\n\nhex()/oct()\n\"bigint\" overrides these routines with versions that can also handle\nbig integer values. Under Perl prior to version v5.9.4, however, this\nwill not happen unless you specifically ask for it with the two\nimport tags \"hex\" and \"oct\" - and then it will be global and cannot\nbe disabled inside a scope with \"no bigint\":\n\nuse bigint qw/hex oct/;\n\nprint hex(\"0x1234567890123456\");\n{\nno bigint;\nprint hex(\"0x1234567890123456\");\n}\n\nThe second call to hex() will warn about a non-portable constant.\n\nCompare this to:\n\nuse bigint;\n\n# will warn only under older than v5.9.4\nprint hex(\"0x1234567890123456\");\n",
                "subsections": []
            },
            "MODULES USED": {
                "content": "\"bignum\" is just a thin wrapper around various modules of the\nMath::BigInt family. Think of it as the head of the family, who runs\nthe shop, and orders the others to do the work.\n\nThe following modules are currently used by bignum:\n\nMath::BigInt::Lite      (for speed, and only if it is loadable)\nMath::BigInt\nMath::BigFloat\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "Some cool command line examples to impress the Python crowd ;)\n\nperl -Mbignum -le 'print sqrt(33)'\nperl -Mbignum -le 'print 2*255'\nperl -Mbignum -le 'print 4.5+2*255'\nperl -Mbignum -le 'print 3/7 + 5/7 + 8/3'\nperl -Mbignum -le 'print 123->isodd()'\nperl -Mbignum -le 'print log(2)'\nperl -Mbignum -le 'print exp(1)'\nperl -Mbignum -le 'print 2  0.5'\nperl -Mbignum=a,65 -le 'print 2  0.2'\nperl -Mbignum=a,65,l,GMP -le 'print 7  7777'\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Please report any bugs or feature requests to \"bug-math-bigint at\nrt.cpan.org\", or through the web interface at\n<https://rt.cpan.org/Ticket/Create.html?Queue=bignum> (requires login).\nWe will be notified, and then you'll automatically be notified of\nprogress on your bug as I make changes.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "You can find documentation for this module with the perldoc command.\n\nperldoc bignum\n\nYou can also look for information at:\n\no   RT: CPAN's request tracker\n\n<https://rt.cpan.org/Public/Dist/Display.html?Name=bignum>\n\no   AnnoCPAN: Annotated CPAN documentation\n\n<http://annocpan.org/dist/bignum>\n\no   CPAN Ratings\n\n<http://cpanratings.perl.org/dist/bignum>\n\no   Search CPAN\n\n<http://search.cpan.org/dist/bignum/>\n\no   CPAN Testers Matrix\n\n<http://matrix.cpantesters.org/?dist=bignum>\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This program is free software; you may redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "bigint and bigrat.\n\nMath::BigInt, Math::BigFloat, Math::BigRat and Math::Big as well as\nMath::BigInt::FastCalc, Math::BigInt::Pari and Math::BigInt::GMP.\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "o   (C) by Tels <http://bloodgate.com/> in early 2002 - 2007.\n\no   Maintained by Peter John Acklam <pjacklam@gmail.com<gt>, 2014-.\n\nperl v5.34.0                      2026-06-23                     bignum(3perl)",
                "subsections": []
            }
        }
    }
}