{
    "mode": "perldoc",
    "parameter": "bigfloat",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/bigfloat/json",
    "generated": "2026-10-04T20:16:37Z",
    "synopsis": "use bigfloat;\n$x = 2 + 4.5;                       # Math::BigFloat 6.5\nprint 2  512 * 0.1;               # Math::BigFloat 134...09.6\nprint inf + 42;                     # Math::BigFloat inf\nprint NaN * 7;                      # Math::BigFloat NaN\nprint hex(\"0x1234567890123490\");    # Perl v5.10.0 or later\n{\nno bigfloat;\nprint 2  256;                 # a normal Perl scalar now\n}\n# for older Perls, import into current package:\nuse bigfloat qw/hex oct/;\nprint hex(\"0x1234567890123490\");\nprint oct(\"01234567890123490\");",
    "sections": {
        "NAME": {
            "content": "bigfloat - transparent big floating point number support for Perl\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use bigfloat;\n\n$x = 2 + 4.5;                       # Math::BigFloat 6.5\nprint 2  512 * 0.1;               # Math::BigFloat 134...09.6\nprint inf + 42;                     # Math::BigFloat inf\nprint NaN * 7;                      # Math::BigFloat NaN\nprint hex(\"0x1234567890123490\");    # Perl v5.10.0 or later\n\n{\nno bigfloat;\nprint 2  256;                 # a normal Perl scalar now\n}\n\n# for older Perls, import into current package:\nuse bigfloat qw/hex oct/;\nprint hex(\"0x1234567890123490\");\nprint oct(\"01234567890123490\");\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "All numeric literals in the given scope are converted to Math::BigFloat objects.\n\nAll operators (including basic math operations) except the range operator \"..\" are overloaded.\n\nSo, the following:\n\nuse bigfloat;\n$x = 1234;\n\ncreates a Math::BigFloat and stores a reference to in $x. This happens transparently and behind\nyour back, so to speak.\n\nYou can see this with the following:\n\nperl -Mbigfloat -le 'print ref(1234)'\n\nSince numbers are actually objects, you can call all the usual methods from Math::BigFloat on\nthem. This even works to some extent on expressions:\n\nperl -Mbigfloat -le '$x = 1234; print $x->bdec()'\nperl -Mbigfloat -le 'print 1234->copy()->binc();'\nperl -Mbigfloat -le 'print 1234->copy()->binc->badd(6);'\nperl -Mbigfloat -le 'print +(1234)->copy()->binc()'\n\n(Note that print doesn't do what you expect if the expression starts with '(' hence the \"+\")\n\nYou can even chain the operations together as usual:\n\nperl -Mbigfloat -le 'print 1234->copy()->binc->badd(6);'\n1241\n\nPlease note the following does not work as expected (prints nothing), since overloading of '..'\nis not yet possible in Perl (as of v5.8.0):\n\nperl -Mbigfloat -le 'for (1..2) { print ref($); }'\n",
            "subsections": [
                {
                    "name": "Options",
                    "content": "\"bigfloat\" recognizes some options that can be passed while loading it via via \"use\". The\nfollowing options exist:\n\na or accuracy\nThis sets the accuracy for all math operations. The argument must be greater than or equal\nto zero. See Math::BigInt's bround() method for details.\n\nperl -Mbigfloat=a,50 -le 'print sqrt(20)'\n\nNote that setting precision and accuracy at the same time is not possible.\n\np or precision\nThis sets the precision for all math operations. The argument can be any integer. Negative\nvalues mean a fixed number of digits after the dot, while a positive value rounds to this\ndigit left from the dot. 0 means round to integer. See Math::BigInt's bfround() method for\ndetails.\n\nperl -Mbigfloat=p,-50 -le 'print sqrt(20)'\n\nNote that setting precision and accuracy at the same time is not possible.\n\nt or trace\nThis enables a trace mode and is primarily for debugging.\n\nl, lib, try, or only\nLoad a different math lib, see \"Math Library\".\n\nperl -Mbigfloat=l,GMP -e 'print 2  512'\nperl -Mbigfloat=lib,GMP -e 'print 2  512'\nperl -Mbigfloat=try,GMP -e 'print 2  512'\nperl -Mbigfloat=only,GMP -e 'print 2  512'\n\nhex Override the built-in hex() method with a version that can handle big numbers. This\noverrides it by exporting it to the current package. Under Perl v5.10.0 and higher, this is\nnot so necessary, as hex() is lexically overridden in the current scope whenever the\n\"bigfloat\" pragma is active.\n\noct Override the built-in oct() method with a version that can handle big numbers. This\noverrides it by exporting it to the current package. Under Perl v5.10.0 and higher, this is\nnot so necessary, as oct() is lexically overridden in the current scope whenever the\n\"bigfloat\" pragma is active.\n\nv or version\nthis prints out the name and version of the modules and then exits.\n\nperl -Mbigfloat=v\n"
                },
                {
                    "name": "Math Library",
                    "content": "Math with the numbers is done (by default) by a backend library module called\nMath::BigInt::Calc. The default is equivalent to saying:\n\nuse bigfloat lib => 'Calc';\n\nyou can change this by using:\n\nuse bigfloat lib => 'GMP';\n\nThe following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and if this\nalso fails, revert to Math::BigInt::Calc:\n\nuse bigfloat lib => 'Foo,Math::BigInt::Bar';\n\nUsing c<lib> warns if none of the specified libraries can be found and Math::BigInt fell back to\none of the default libraries. To suppress this warning, use c<try> instead:\n\nuse bigfloat try => 'GMP';\n\nIf you want the code to die instead of falling back, use \"only\" instead:\n\nuse bigfloat only => 'GMP';\n\nPlease see respective module documentation for further details.\n"
                },
                {
                    "name": "Method calls",
                    "content": "Since all numbers are now objects, you can use all methods that are part of the Math::BigFloat\nAPI.\n\nBut a warning is in order. When using the following to make a copy of a number, only a shallow\ncopy will be made.\n\n$x = 9; $y = $x;\n$x = $y = 7;\n\nUsing the copy or the original with overloaded math is okay, e.g., the following 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 both the original and\nthe 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 that 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, as well as the\ndocumentation in Math::BigFloat for further details.\n"
                },
                {
                    "name": "Methods",
                    "content": ""
                },
                {
                    "name": "inf",
                    "content": "A shortcut to return Math::BigFloat->binf(). Useful because Perl does not always handle\nbareword \"inf\" properly.\n\nNaN()\nA shortcut to return Math::BigFloat->bnan(). Useful because Perl does not always handle\nbareword \"NaN\" properly.\n\ne\n# perl -Mbigfloat=e -wle 'print e'\n\nReturns Euler's number \"e\", aka exp(1)\n\nPI\n# perl -Mbigfloat=PI -wle 'print PI'\n\nReturns PI.\n"
                },
                {
                    "name": "bexp",
                    "content": "bexp($power, $accuracy);\n\nReturns Euler's number \"e\" raised to the appropriate power, to the wanted accuracy.\n\nExample:\n\n# perl -Mbigfloat=bexp -wle 'print bexp(1,80)'\n"
                },
                {
                    "name": "bpi",
                    "content": "bpi($accuracy);\n\nReturns PI to the wanted accuracy.\n\nExample:\n\n# perl -Mbigfloat=bpi -wle 'print bpi(80)'\n"
                },
                {
                    "name": "accuracy",
                    "content": "Set or get the accuracy.\n"
                },
                {
                    "name": "precision",
                    "content": "Set or get the precision.\n"
                },
                {
                    "name": "round_mode",
                    "content": "Set or get the rounding mode.\n"
                },
                {
                    "name": "div_scale",
                    "content": "Set or get the division scale.\n"
                },
                {
                    "name": "upgrade",
                    "content": "Set or get the class that the downgrade class upgrades to, if any. Set the upgrade class to\n\"undef\" to disable upgrading.\n\nUpgrading is disabled by default.\n"
                },
                {
                    "name": "downgrade",
                    "content": "Set or get the class that the upgrade class downgrades to, if any. Set the downgrade class\nto \"undef\" to disable upgrading.\n\nDowngrading is disabled by default.\n"
                },
                {
                    "name": "in_effect",
                    "content": "use bigfloat;\n\nprint \"in effect\\n\" if bigfloat::ineffect;       # true\n{\nno bigfloat;\nprint \"in effect\\n\" if bigfloat::ineffect;   # false\n}\n\nReturns true or false if \"bigfloat\" is in effect in the current scope.\n\nThis method only works on Perl v5.9.4 or later.\n"
                }
            ]
        },
        "CAVEATS": {
            "content": "Hexadecimal, octal, and binary floating point literals\nPerl (and this module) accepts hexadecimal, octal, and binary floating point literals, but\nuse them with care with Perl versions before v5.32.0, because some versions of Perl silently\ngive the wrong result.\n\nOperator vs literal overloading\n\"bigrat\" works by overloading handling of integer and floating point literals, converting\nthem to Math::BigRat objects.\n\nThis means that arithmetic involving only string values or string literals are performed\nusing Perl's built-in operators.\n\nFor example:\n\nuse bigrat;\nmy $x = \"900000000000000009\";\nmy $y = \"900000000000000007\";\nprint $x - $y;\n\noutputs 0 on default 32-bit builds, since \"bigfloat\" never sees the string literals. To\nensure the expression is all treated as \"Math::BigFloat\" objects, use a literal number in\nthe expression:\n\nprint +(0+$x) - $y;\n\nRanges\nPerl does not allow overloading of ranges, so you can neither safely use ranges with\n\"bigfloat\" endpoints, nor is the iterator variable a \"Math::BigFloat\".\n\nuse 5.010;\nfor my $i (12..13) {\nfor my $j (20..21) {\nsay $i  $j;  # produces a floating-point number,\n# not an object\n}\n}\n",
            "subsections": [
                {
                    "name": "in_effect",
                    "content": "This method only works on Perl v5.9.4 or later.\n"
                },
                {
                    "name": "hex",
                    "content": "\"bigfloat\" overrides these routines with versions that can also handle big integer values.\nUnder Perl prior to version v5.9.4, however, this will not happen unless you specifically\nask for it with the two import tags \"hex\" and \"oct\" - and then it will be global and cannot\nbe disabled inside a scope with \"no bigfloat\":\n\nuse bigfloat qw/hex oct/;\n\nprint hex(\"0x1234567890123456\");\n{\nno bigfloat;\nprint hex(\"0x1234567890123456\");\n}\n\nThe second call to hex() will warn about a non-portable constant.\n\nCompare this to:\n\nuse bigfloat;\n\n# will warn only under Perl older than v5.9.4\nprint hex(\"0x1234567890123456\");\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "Some cool command line examples to impress the Python crowd ;)\n\nperl -Mbigfloat -le 'print sqrt(33)'\nperl -Mbigfloat -le 'print 2255'\nperl -Mbigfloat -le 'print 4.5+2255'\nperl -Mbigfloat -le 'print 3/7 + 5/7 + 8/3'\nperl -Mbigfloat -le 'print 123->isodd()'\nperl -Mbigfloat -le 'print log(2)'\nperl -Mbigfloat -le 'print exp(1)'\nperl -Mbigfloat -le 'print 2  0.5'\nperl -Mbigfloat=a,65 -le 'print 2  0.2'\nperl -Mbigfloat=l,GMP -le 'print 7  7777'\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Please report any bugs or feature requests to \"bug-bignum at rt.cpan.org\", or through the web\ninterface at <https://rt.cpan.org/Ticket/Create.html?Queue=bignum> (requires login). We will be\nnotified, and then you'll automatically be notified of progress on your bug as I make changes.\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "You can find documentation for this module with the perldoc command.\n\nperldoc bigfloat\n\nYou can also look for information at:\n\n*   GitHub\n\n<https://github.com/pjacklam/p5-bignum>\n\n*   RT: CPAN's request tracker\n\n<https://rt.cpan.org/Dist/Display.html?Name=bignum>\n\n*   MetaCPAN\n\n<https://metacpan.org/release/bignum>\n\n*   CPAN Testers Matrix\n\n<http://matrix.cpantesters.org/?dist=bignum>\n\n*   CPAN Ratings\n\n<https://cpanratings.perl.org/dist/bignum>\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This program is free software; you may redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "bigint and bigrat.\n\nMath::BigInt, Math::BigFloat, Math::BigRat and Math::Big as well as Math::BigInt::FastCalc,\nMath::BigInt::Pari and Math::BigInt::GMP.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   (C) by Tels <http://bloodgate.com/> in early 2002 - 2007.\n\n*   Maintained by Peter John Acklam <pjacklam@gmail.com>, 2014-.\n",
            "subsections": []
        }
    },
    "summary": "bigfloat - transparent big floating point number support for Perl",
    "flags": [],
    "examples": [
        "Some cool command line examples to impress the Python crowd ;)",
        "perl -Mbigfloat -le 'print sqrt(33)'",
        "perl -Mbigfloat -le 'print 2255'",
        "perl -Mbigfloat -le 'print 4.5+2255'",
        "perl -Mbigfloat -le 'print 3/7 + 5/7 + 8/3'",
        "perl -Mbigfloat -le 'print 123->isodd()'",
        "perl -Mbigfloat -le 'print log(2)'",
        "perl -Mbigfloat -le 'print exp(1)'",
        "perl -Mbigfloat -le 'print 2  0.5'",
        "perl -Mbigfloat=a,65 -le 'print 2  0.2'",
        "perl -Mbigfloat=l,GMP -le 'print 7  7777'"
    ],
    "see_also": []
}