CINXE.COM
bignum - transparent big number support for Perl - metacpan.org
<!DOCTYPE html> <html lang="en-US"> <head> <title>bignum - transparent big number support for Perl - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of bignum - MetaCPAN" href="/dist/bignum/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/bignum" /> <meta name="description" content="transparent big number support for Perl" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/bignum" /> <meta property="og:title" content="bignum" /> <meta property="og:description" content="transparent big number support for Perl" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of bignum was released."> <span class="relatize">30 Dec 2023 13:48:09 UTC</span> </div> </li> <li> Distribution: <a href="/dist/bignum">bignum</a> </li> <li> Module version: 0.67 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/bignum/source/lib/bignum.pm">Source</a> (<a href="/dist/bignum/source/lib/bignum.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/bignum/source/lib">Browse</a> (<a href="/dist/bignum/source/lib?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/bignum/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/bignum/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/pjacklam/p5-bignum">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=bignum">Issues</a> (1) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=bignum+0.67" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/b/bignum.html?oncpan=1&distmat=1&version=0.67&grade=2" style="color: #090">1657</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/b/bignum.html?oncpan=1&distmat=1&version=0.67&grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/b/bignum.html?oncpan=1&distmat=1&version=0.67&grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/PJACKLAM/bignum-0.67">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on bignum who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 5 </div> </li> <li> License: perl_5 </li> <li> Perl: v5.6.0 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/bignum/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/P/PJ/PJACKLAM/bignum-0.67.tar.gz"> Download (<span itemprop="fileSize">41.24KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FPJACKLAM%2Fbignum-0.67%2Flib%2Fbignum.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/bignum/permissions"> Permissions </a> </li> <li> <a href="/dist/bignum/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:bignum"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="bignum"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/PJACKLAM/bignum-0.67/view/lib/bignum.pm" >0.67 (PJACKLAM on 2023-12-30)</option> <option value="/release/PJACKLAM/bignum-0.66/view/lib/bignum.pm" >0.66 (PJACKLAM on 2022-05-16)</option> <option value="/release/PJACKLAM/bignum-0.65/view/lib/bignum.pm" >0.65 (PJACKLAM on 2022-04-12)</option> <option value="/release/FLORA/bignum-0.32/view/lib/bignum.pm" >0.32 (FLORA on 2013-03-02)</option> <option value="/release/FLORA/bignum-0.30/view/lib/bignum.pm" >0.30 (FLORA on 2012-09-11)</option> <option value="/release/FLORA/bignum-0.29/view/lib/bignum.pm" >0.29 (FLORA on 2011-08-08)</option> <option value="/release/FLORA/bignum-0.28/view/lib/bignum.pm" >0.28 (FLORA on 2011-07-09)</option> <option value="/release/FLORA/bignum-0.25/view/lib/bignum.pm" >0.25 (FLORA on 2010-09-15)</option> <option value="/release/FLORA/bignum-0.24/view/lib/bignum.pm" >0.24 (FLORA on 2010-09-04)</option> <option value="/release/TELS/bignum-0.23/view/lib/bignum.pm" >0.23 (TELS on 2008-04-05)</option> <option value="/release/TELS/bignum-0.22/view/lib/bignum.pm" >0.22 (TELS on 2007-06-30)</option> <optgroup label="BackPAN">' <option value="/release/PJACKLAM/bignum-0.64/view/lib/bignum.pm" >0.64 (PJACKLAM on 2021-12-28)</option> <option value="/release/PJACKLAM/bignum-0.63/view/lib/bignum.pm" >0.63 (PJACKLAM on 2021-10-09)</option> <option value="/release/PJACKLAM/bignum-0.62/view/lib/bignum.pm" >0.62 (PJACKLAM on 2021-10-03)</option> <option value="/release/PJACKLAM/bignum-0.61/view/lib/bignum.pm" >0.61 (PJACKLAM on 2021-10-01)</option> <option value="/release/PJACKLAM/bignum-0.60/view/lib/bignum.pm" >0.60 (PJACKLAM on 2021-09-29)</option> <option value="/release/PJACKLAM/bignum-0.53/view/lib/bignum.pm" >0.53 (PJACKLAM on 2021-07-12)</option> <option value="/release/PJACKLAM/bignum-0.52/view/lib/bignum.pm" >0.52 (PJACKLAM on 2021-07-10)</option> <option value="/release/PJACKLAM/bignum-0.51/view/lib/bignum.pm" >0.51 (PJACKLAM on 2018-10-11)</option> <option value="/release/PJACKLAM/bignum-0.50/view/lib/bignum.pm" >0.50 (PJACKLAM on 2018-04-17)</option> <option value="/release/PJACKLAM/bignum-0.49/view/lib/bignum.pm" >0.49 (PJACKLAM on 2018-02-04)</option> <option value="/release/PJACKLAM/bignum-0.48/view/lib/bignum.pm" >0.48 (PJACKLAM on 2018-02-01)</option> <option value="/release/PJACKLAM/bignum-0.47/view/lib/bignum.pm" >0.47 (PJACKLAM on 2016-12-13)</option> <option value="/release/PJACKLAM/bignum-0.46/view/lib/bignum.pm" >0.46 (PJACKLAM on 2016-12-11)</option> <option value="/release/PJACKLAM/bignum-0.45/view/lib/bignum.pm" >0.45 (PJACKLAM on 2016-12-04)</option> <option value="/release/PJACKLAM/bignum-0.44/view/lib/bignum.pm" >0.44 (PJACKLAM on 2016-11-17)</option> <option value="/release/PJACKLAM/bignum-0.43/view/lib/bignum.pm" >0.43 (PJACKLAM on 2016-07-09)</option> <option value="/release/PJACKLAM/bignum-0.42/view/lib/bignum.pm" >0.42 (PJACKLAM on 2016-01-05)</option> <option value="/release/PJACKLAM/bignum-0.41/view/lib/bignum.pm" >0.41 (PJACKLAM on 2015-09-25)</option> <option value="/release/PJACKLAM/bignum-0.40/view/lib/bignum.pm" >0.40 (PJACKLAM on 2015-09-23)</option> <option value="/release/PJACKLAM/bignum-0.39/view/lib/bignum.pm" >0.39 (PJACKLAM on 2015-09-15)</option> <option value="/release/PJACKLAM/bignum-0.38/view/lib/bignum.pm" >0.38 (PJACKLAM on 2015-08-28)</option> <option value="/release/PJACKLAM/bignum-0.37/view/lib/bignum.pm" >0.37 (PJACKLAM on 2014-04-04)</option> <option value="/release/TELS/bignum-0.21/view/lib/bignum.pm" >0.21 (TELS on 2007-04-17)</option> <option value="/release/TELS/bignum-0.20/view/lib/bignum.pm" >0.20 (TELS on 2007-04-09)</option> <option value="/release/TELS/bignum-0.19/view/lib/bignum.pm" >0.19 (TELS on 2007-02-03)</option> <option value="/release/TELS/bignum-0.18/view/lib/bignum.pm" >0.18 (TELS on 2007-01-28)</option> <option value="/release/TELS/bignum-0.17/view/lib/bignum.pm" >0.17 (TELS on 2005-04-10)</option> <option value="/release/TELS/bignum-0.16/view/lib/bignum.pm" >0.16 (TELS on 2005-01-01)</option> <option value="/release/TELS/bignum-0.15/view/lib/bignum.pm" >0.15 (TELS on 2004-03-12)</option> <option value="/release/TELS/bignum-0.14/view/lib/bignum.pm" >0.14 (TELS on 2003-08-13)</option> <option value="/release/TELS/bignum-0.13/view/lib/bignum.pm" >0.13 (TELS on 2002-08-24)</option> <option value="/release/TELS/bignum-0.12/view/lib/bignum.pm" >0.12 (TELS on 2002-08-13)</option> <option value="/release/TELS/bignum-0.11/view/lib/bignum.pm" >0.11 (TELS on 2002-03-26)</option> <option value="/release/TELS/bignum-0.10/view/lib/bignum.pm" >0.10 (TELS on 2002-03-17)</option> <option value="/release/TELS/bignum-0.09/view/lib/bignum.pm" >0.09 (TELS on 2002-03-12)</option> <option value="/release/TELS/bignum-0.08/view/lib/bignum.pm" >0.08 (TELS on 2002-03-11)</option> <option value="/release/TELS/bignum-0.07/view/lib/bignum.pm" >0.07 (TELS on 2002-03-06)</option> <option value="/release/TELS/bignum-0.06/view/lib/bignum.pm" >0.06 (TELS on 2002-02-27)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.67/lib/bignum.pm" >0.67 (PJACKLAM on 2023-12-30)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.66/lib/bignum.pm" >0.66 (PJACKLAM on 2022-05-16)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.65/lib/bignum.pm" >0.65 (PJACKLAM on 2022-04-12)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.32/lib/bignum.pm" >0.32 (FLORA on 2013-03-02)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.30/lib/bignum.pm" >0.30 (FLORA on 2012-09-11)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.29/lib/bignum.pm" >0.29 (FLORA on 2011-08-08)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.28/lib/bignum.pm" >0.28 (FLORA on 2011-07-09)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.25/lib/bignum.pm" >0.25 (FLORA on 2010-09-15)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/FLORA/bignum-0.24/lib/bignum.pm" >0.24 (FLORA on 2010-09-04)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.23/lib/bignum.pm" >0.23 (TELS on 2008-04-05)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.22/lib/bignum.pm" >0.22 (TELS on 2007-06-30)</option> <optgroup label="BackPAN">' <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.64/lib/bignum.pm" >0.64 (PJACKLAM on 2021-12-28)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.63/lib/bignum.pm" >0.63 (PJACKLAM on 2021-10-09)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.62/lib/bignum.pm" >0.62 (PJACKLAM on 2021-10-03)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.61/lib/bignum.pm" >0.61 (PJACKLAM on 2021-10-01)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.60/lib/bignum.pm" >0.60 (PJACKLAM on 2021-09-29)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.53/lib/bignum.pm" >0.53 (PJACKLAM on 2021-07-12)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.52/lib/bignum.pm" >0.52 (PJACKLAM on 2021-07-10)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.51/lib/bignum.pm" >0.51 (PJACKLAM on 2018-10-11)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.50/lib/bignum.pm" >0.50 (PJACKLAM on 2018-04-17)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.49/lib/bignum.pm" >0.49 (PJACKLAM on 2018-02-04)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.48/lib/bignum.pm" >0.48 (PJACKLAM on 2018-02-01)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.47/lib/bignum.pm" >0.47 (PJACKLAM on 2016-12-13)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.46/lib/bignum.pm" >0.46 (PJACKLAM on 2016-12-11)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.45/lib/bignum.pm" >0.45 (PJACKLAM on 2016-12-04)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.44/lib/bignum.pm" >0.44 (PJACKLAM on 2016-11-17)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.43/lib/bignum.pm" >0.43 (PJACKLAM on 2016-07-09)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.42/lib/bignum.pm" >0.42 (PJACKLAM on 2016-01-05)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.41/lib/bignum.pm" >0.41 (PJACKLAM on 2015-09-25)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.40/lib/bignum.pm" >0.40 (PJACKLAM on 2015-09-23)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.39/lib/bignum.pm" >0.39 (PJACKLAM on 2015-09-15)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.38/lib/bignum.pm" >0.38 (PJACKLAM on 2015-08-28)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/PJACKLAM/bignum-0.37/lib/bignum.pm" >0.37 (PJACKLAM on 2014-04-04)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.21/lib/bignum.pm" >0.21 (TELS on 2007-04-17)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.20/lib/bignum.pm" >0.20 (TELS on 2007-04-09)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.19/lib/bignum.pm" >0.19 (TELS on 2007-02-03)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.18/lib/bignum.pm" >0.18 (TELS on 2007-01-28)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.17/lib/bignum.pm" >0.17 (TELS on 2005-04-10)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.16/lib/bignum.pm" >0.16 (TELS on 2005-01-01)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.15/lib/bignum.pm" >0.15 (TELS on 2004-03-12)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.14/lib/bignum.pm" >0.14 (TELS on 2003-08-13)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.13/lib/bignum.pm" >0.13 (TELS on 2002-08-24)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.12/lib/bignum.pm" >0.12 (TELS on 2002-08-13)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.11/lib/bignum.pm" >0.11 (TELS on 2002-03-26)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.10/lib/bignum.pm" >0.10 (TELS on 2002-03-17)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.09/lib/bignum.pm" >0.09 (TELS on 2002-03-12)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.08/lib/bignum.pm" >0.08 (TELS on 2002-03-11)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.07/lib/bignum.pm" >0.07 (TELS on 2002-03-06)</option> <option value="/release/PJACKLAM/bignum-0.67/diff/TELS/bignum-0.06/lib/bignum.pm" >0.06 (TELS on 2002-02-27)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/Carp" title="Carp" class="ellipsis">Carp</a></li> <li><a href="/pod/Math::BigInt" title="Math::BigInt" class="ellipsis">Math::BigInt</a></li> <li><a href="/pod/Math::BigRat" title="Math::BigRat" class="ellipsis">Math::BigRat</a></li> <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li> <li> <hr> </li> <li> <a href="/module/bignum/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=bignum">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=bignum">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/PJACKLAM/bignum-0.67/view/lib/bignum.pm">This version</a> </li> <li> <a href="/pod/bignum">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/PINGAN"><img src="https://www.gravatar.com/avatar/a02222e5e0e4fd24d52fc29a08ac6bcb?d=identicon&s=20" title="PINGAN" alt="PINGAN"></a> <a class="display-all" href="/author/PAWAPAWA"><img src="https://www.gravatar.com/avatar/96d37e9730b6fe228338ce866c103daa?d=identicon&s=20" title="PAWAPAWA" alt="PAWAPAWA"></a> <a class="display-all" href="/author/NGLENN"><img src="https://www.gravatar.com/avatar/d760ed3250a704f6ae9e2c9b4d73cc1f?d=identicon&s=20" title="NGLENN" alt="NGLENN"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/bignum/plussers">3 PAUSE users</a> </div> <div> 1 non-PAUSE user </div> </div> </li> <li> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/PJACKLAM" class="author-name">Peter John Acklam</a> </span> <span> / </span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/PJACKLAM/bignum-0.67/view/lib/bignum.pm" >0.67 (PJACKLAM on 2023-12-30)</option> <option value="/release/PJACKLAM/bignum-0.66/view/lib/bignum.pm" >0.66 (PJACKLAM on 2022-05-16)</option> <option value="/release/PJACKLAM/bignum-0.65/view/lib/bignum.pm" >0.65 (PJACKLAM on 2022-04-12)</option> <option value="/release/FLORA/bignum-0.32/view/lib/bignum.pm" >0.32 (FLORA on 2013-03-02)</option> <option value="/release/FLORA/bignum-0.30/view/lib/bignum.pm" >0.30 (FLORA on 2012-09-11)</option> <option value="/release/FLORA/bignum-0.29/view/lib/bignum.pm" >0.29 (FLORA on 2011-08-08)</option> <option value="/release/FLORA/bignum-0.28/view/lib/bignum.pm" >0.28 (FLORA on 2011-07-09)</option> <option value="/release/FLORA/bignum-0.25/view/lib/bignum.pm" >0.25 (FLORA on 2010-09-15)</option> <option value="/release/FLORA/bignum-0.24/view/lib/bignum.pm" >0.24 (FLORA on 2010-09-04)</option> <option value="/release/TELS/bignum-0.23/view/lib/bignum.pm" >0.23 (TELS on 2008-04-05)</option> <option value="/release/TELS/bignum-0.22/view/lib/bignum.pm" >0.22 (TELS on 2007-06-30)</option> <optgroup label="BackPAN">' <option value="/release/PJACKLAM/bignum-0.64/view/lib/bignum.pm" >0.64 (PJACKLAM on 2021-12-28)</option> <option value="/release/PJACKLAM/bignum-0.63/view/lib/bignum.pm" >0.63 (PJACKLAM on 2021-10-09)</option> <option value="/release/PJACKLAM/bignum-0.62/view/lib/bignum.pm" >0.62 (PJACKLAM on 2021-10-03)</option> <option value="/release/PJACKLAM/bignum-0.61/view/lib/bignum.pm" >0.61 (PJACKLAM on 2021-10-01)</option> <option value="/release/PJACKLAM/bignum-0.60/view/lib/bignum.pm" >0.60 (PJACKLAM on 2021-09-29)</option> <option value="/release/PJACKLAM/bignum-0.53/view/lib/bignum.pm" >0.53 (PJACKLAM on 2021-07-12)</option> <option value="/release/PJACKLAM/bignum-0.52/view/lib/bignum.pm" >0.52 (PJACKLAM on 2021-07-10)</option> <option value="/release/PJACKLAM/bignum-0.51/view/lib/bignum.pm" >0.51 (PJACKLAM on 2018-10-11)</option> <option value="/release/PJACKLAM/bignum-0.50/view/lib/bignum.pm" >0.50 (PJACKLAM on 2018-04-17)</option> <option value="/release/PJACKLAM/bignum-0.49/view/lib/bignum.pm" >0.49 (PJACKLAM on 2018-02-04)</option> <option value="/release/PJACKLAM/bignum-0.48/view/lib/bignum.pm" >0.48 (PJACKLAM on 2018-02-01)</option> <option value="/release/PJACKLAM/bignum-0.47/view/lib/bignum.pm" >0.47 (PJACKLAM on 2016-12-13)</option> <option value="/release/PJACKLAM/bignum-0.46/view/lib/bignum.pm" >0.46 (PJACKLAM on 2016-12-11)</option> <option value="/release/PJACKLAM/bignum-0.45/view/lib/bignum.pm" >0.45 (PJACKLAM on 2016-12-04)</option> <option value="/release/PJACKLAM/bignum-0.44/view/lib/bignum.pm" >0.44 (PJACKLAM on 2016-11-17)</option> <option value="/release/PJACKLAM/bignum-0.43/view/lib/bignum.pm" >0.43 (PJACKLAM on 2016-07-09)</option> <option value="/release/PJACKLAM/bignum-0.42/view/lib/bignum.pm" >0.42 (PJACKLAM on 2016-01-05)</option> <option value="/release/PJACKLAM/bignum-0.41/view/lib/bignum.pm" >0.41 (PJACKLAM on 2015-09-25)</option> <option value="/release/PJACKLAM/bignum-0.40/view/lib/bignum.pm" >0.40 (PJACKLAM on 2015-09-23)</option> <option value="/release/PJACKLAM/bignum-0.39/view/lib/bignum.pm" >0.39 (PJACKLAM on 2015-09-15)</option> <option value="/release/PJACKLAM/bignum-0.38/view/lib/bignum.pm" >0.38 (PJACKLAM on 2015-08-28)</option> <option value="/release/PJACKLAM/bignum-0.37/view/lib/bignum.pm" >0.37 (PJACKLAM on 2014-04-04)</option> <option value="/release/TELS/bignum-0.21/view/lib/bignum.pm" >0.21 (TELS on 2007-04-17)</option> <option value="/release/TELS/bignum-0.20/view/lib/bignum.pm" >0.20 (TELS on 2007-04-09)</option> <option value="/release/TELS/bignum-0.19/view/lib/bignum.pm" >0.19 (TELS on 2007-02-03)</option> <option value="/release/TELS/bignum-0.18/view/lib/bignum.pm" >0.18 (TELS on 2007-01-28)</option> <option value="/release/TELS/bignum-0.17/view/lib/bignum.pm" >0.17 (TELS on 2005-04-10)</option> <option value="/release/TELS/bignum-0.16/view/lib/bignum.pm" >0.16 (TELS on 2005-01-01)</option> <option value="/release/TELS/bignum-0.15/view/lib/bignum.pm" >0.15 (TELS on 2004-03-12)</option> <option value="/release/TELS/bignum-0.14/view/lib/bignum.pm" >0.14 (TELS on 2003-08-13)</option> <option value="/release/TELS/bignum-0.13/view/lib/bignum.pm" >0.13 (TELS on 2002-08-24)</option> <option value="/release/TELS/bignum-0.12/view/lib/bignum.pm" >0.12 (TELS on 2002-08-13)</option> <option value="/release/TELS/bignum-0.11/view/lib/bignum.pm" >0.11 (TELS on 2002-03-26)</option> <option value="/release/TELS/bignum-0.10/view/lib/bignum.pm" >0.10 (TELS on 2002-03-17)</option> <option value="/release/TELS/bignum-0.09/view/lib/bignum.pm" >0.09 (TELS on 2002-03-12)</option> <option value="/release/TELS/bignum-0.08/view/lib/bignum.pm" >0.08 (TELS on 2002-03-11)</option> <option value="/release/TELS/bignum-0.07/view/lib/bignum.pm" >0.07 (TELS on 2002-03-06)</option> <option value="/release/TELS/bignum-0.06/view/lib/bignum.pm" >0.06 (TELS on 2002-02-27)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/bignum">bignum-0.67</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage three • 31 direct dependents • 494 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="10" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="15" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="bignum-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="bignum-0.67"> <input type="hidden" name="author" value="PJACKLAM"> <input type="hidden" name="distribution" value="bignum"> <button type="submit" class="favorite highlight"><span>4</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>4</span> ++</button> </div> / <span>bignum</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a> <ul> <li><a href="#Literal-numeric-constants">Literal numeric constants</a></li> <li><a href="#Upgrading-and-downgrading">Upgrading and downgrading</a></li> <li><a href="#Overloading">Overloading</a></li> <li><a href="#Options">Options</a></li> <li><a href="#Math-Library">Math Library</a></li> <li><a href="#Method-calls">Method calls</a></li> <li><a href="#Methods">Methods</a></li> </ul> </li> <li><a href="#CAVEATS">CAVEATS</a></li> <li><a href="#EXAMPLES">EXAMPLES</a></li> <li><a href="#BUGS">BUGS</a></li> <li><a href="#SUPPORT">SUPPORT</a></li> <li><a href="#LICENSE">LICENSE</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHORS">AUTHORS</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>bignum - transparent big number support for Perl</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>use bignum; $x = 2 + 4.5; # Math::BigFloat 6.5 print 2 ** 512 * 0.1; # Math::BigFloat 134...09.6 print 2 ** 512; # Math::BigInt 134...096 print inf + 42; # Math::BigInt inf print NaN * 7; # Math::BigInt NaN print hex("0x1234567890123490"); # Perl v5.10.0 or later { no bignum; print 2 ** 256; # a normal Perl scalar now } # for older Perls, import into current package: use bignum qw/hex oct/; print hex("0x1234567890123490"); print oct("01234567890123490");</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <h2 id="Literal-numeric-constants"><a id="Literal"></a>Literal numeric constants</h2> <p>By default, every literal integer becomes a Math::BigInt object, and literal non-integer becomes a Math::BigFloat object. Whether a numeric literal is considered an integer or non-integers depends only on the value of the constant, not on how it is represented. For instance, the constants 3.14e2 and 0x1.3ap8 become Math::BigInt objects, because they both represent the integer value decimal 314.</p> <p>The default <code>use bignum;</code> is equivalent to</p> <pre><code>use bignum downgrade => "Math::BigInt", upgrade => "Math::BigFloat";</code></pre> <p>The classes used for integers and non-integers can be set at compile time with the <code>downgrade</code> and <code>upgrade</code> options, for example</p> <pre><code># use Math::BigInt for integers and Math::BigRat for non-integers use bignum upgrade => "Math::BigRat";</code></pre> <p>Note that disabling downgrading and upgrading does not affect how numeric literals are converted to objects</p> <pre><code># disable both downgrading and upgrading use bignum downgrade => undef, upgrade => undef; $x = 2.4; # becomes 2.4 as a Math::BigFloat $y = 2; # becomes 2 as a Math::BigInt</code></pre> <h2 id="Upgrading-and-downgrading"><a id="Upgrading"></a>Upgrading and downgrading</h2> <p>By default, when the result of a computation is an integer, an Inf, or a NaN, the result is downgraded even when all the operands are instances of the upgrade class.</p> <pre><code>use bignum; $x = 2.4; # becomes 2.4 as a Math::BigFloat $y = 1.2; # becomes 1.2 as a Math::BigFloat $z = $x / $y; # becomes 2 as a Math::BigInt due to downgrading</code></pre> <p>Equivalently, by default, when the result of a computation is a finite non-integer, the result is upgraded even when all the operands are instances of the downgrade class.</p> <pre><code>use bignum; $x = 7; # becomes 7 as a Math::BigInt $y = 2; # becomes 2 as a Math::BigInt $z = $x / $y; # becomes 3.5 as a Math::BigFloat due to upgrading</code></pre> <p>The classes used for downgrading and upgrading can be set at runtime with the <a href="#downgrade()">"downgrade()"</a> and <a href="#upgrade()">"upgrade()"</a> methods, but see <a href="#CAVEATS">"CAVEATS"</a> below.</p> <p>The upgrade and downgrade classes don't have to be Math::BigInt and Math::BigFloat. For example, to use Math::BigRat as the upgrade class, use</p> <pre><code>use bignum upgrade => "Math::BigRat"; $x = 2; # becomes 2 as a Math::BigInt $y = 3.6; # becomes 18/5 as a Math::BigRat</code></pre> <p>The upgrade and downgrade classes can be modified at runtime</p> <pre><code>use bignum; $x = 3; # becomes 3 as a Math::BigInt $y = 2; # becomes 2 as a Math::BigInt $z = $x / $y; # becomes 1.5 as a Math::BigFlaot bignum -> upgrade("Math::BigRat"); $w = $x / $y; # becomes 3/2 as a Math::BigRat</code></pre> <p>Disabling downgrading doesn't change the fact that literal constant integers are converted to the downgrade class, it only prevents downgrading as a result of a computation. E.g.,</p> <pre><code>use bignum downgrade => undef; $x = 2; # becomes 2 as a Math::BigInt $y = 2.4; # becomes 2.4 as a Math::BigFloat $z = 1.2; # becomes 1.2 as a Math::BigFloat $w = $x / $y; # becomes 2 as a Math::BigFloat due to no downgrading</code></pre> <p>If you want all numeric literals, both integers and non-integers, to become Math::BigFloat objects, use the <a href="/pod/bigfloat">bigfloat</a> pragma.</p> <p>Equivalently, disabling upgrading doesn't change the fact that literal constant non-integers are converted to the upgrade class, it only prevents upgrading as a result of a computation. E.g.,</p> <pre><code>use bignum upgrade => undef; $x = 2.5; # becomes 2.5 as a Math::BigFloat $y = 7; # becomes 7 as a Math::BigInt $z = 2; # becomes 2 as a Math::BigInt $w = $x / $y; # becomes 3 as a Math::BigInt due to no upgrading</code></pre> <p>If you want all numeric literals, both integers and non-integers, to become Math::BigInt objects, use the <a href="/pod/bigint">bigint</a> pragma.</p> <p>You can even do</p> <pre><code>use bignum upgrade => "Math::BigRat", upgrade => undef;</code></pre> <p>which converts all integer literals to Math::BigInt objects and all non-integer literals to Math::BigRat objects. However, when the result of a computation involving two Math::BigInt objects results in a non-integer (e.g., 7/2), the result will be truncted to a Math::BigInt rather than being upgraded to a Math::BigRat, since upgrading is disabled.</p> <h2 id="Overloading">Overloading</h2> <p>Since all numeric literals become objects, you can call all the usual methods from Math::BigInt and Math::BigFloat on them. This even works to some extent on expressions:</p> <pre><code>perl -Mbignum -le '$x = 1234; print $x->bdec()' perl -Mbignum -le 'print 1234->copy()->binc();' perl -Mbignum -le 'print 1234->copy()->binc()->badd(6);'</code></pre> <h2 id="Options">Options</h2> <p><code>bignum</code> recognizes some options that can be passed while loading it via via <code>use</code>. The following options exist:</p> <dl> <dt id="a-or-accuracy"><a id="a"></a>a or accuracy</dt> <dd> <p>This sets the accuracy for all math operations. The argument must be greater than or equal to zero. See Math::BigInt's bround() method for details.</p> <pre><code>perl -Mbignum=a,50 -le 'print sqrt(20)'</code></pre> <p>Note that setting precision and accuracy at the same time is not possible.</p> </dd> <dt id="p-or-precision"><a id="p"></a>p or precision</dt> <dd> <p>This sets the precision for all math operations. The argument can be any integer. Negative values mean a fixed number of digits after the dot, while a positive value rounds to this digit left from the dot. 0 means round to integer. See Math::BigInt's bfround() method for details.</p> <pre><code>perl -Mbignum=p,-50 -le 'print sqrt(20)'</code></pre> <p>Note that setting precision and accuracy at the same time is not possible.</p> </dd> <dt id="l,-lib,-try,-or-only"><a id="l"></a><a id="l-lib-try-or-only"></a>l, lib, try, or only</dt> <dd> <p>Load a different math lib, see <a href="#Math-Library">"Math Library"</a>.</p> <pre><code>perl -Mbignum=l,GMP -e 'print 2 ** 512' perl -Mbignum=lib,GMP -e 'print 2 ** 512' perl -Mbignum=try,GMP -e 'print 2 ** 512' perl -Mbignum=only,GMP -e 'print 2 ** 512'</code></pre> </dd> <dt id="hex">hex</dt> <dd> <p>Override the built-in hex() method with a version that can handle big numbers. This overrides it by exporting it to the current package. Under Perl v5.10.0 and higher, this is not so necessary, as hex() is lexically overridden in the current scope whenever the <code>bignum</code> pragma is active.</p> </dd> <dt id="oct">oct</dt> <dd> <p>Override the built-in oct() method with a version that can handle big numbers. This overrides it by exporting it to the current package. Under Perl v5.10.0 and higher, this is not so necessary, as oct() is lexically overridden in the current scope whenever the <code>bignum</code> pragma is active.</p> </dd> <dt id="v-or-version"><a id="v"></a>v or version</dt> <dd> <p>this prints out the name and version of the modules and then exits.</p> <pre><code>perl -Mbignum=v</code></pre> </dd> </dl> <h2 id="Math-Library"><a id="Math"></a>Math Library</h2> <p>Math with the numbers is done (by default) by a backend library module called Math::BigInt::Calc. The default is equivalent to saying:</p> <pre><code>use bignum lib => 'Calc';</code></pre> <p>you can change this by using:</p> <pre><code>use bignum lib => 'GMP';</code></pre> <p>The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and if this also fails, revert to Math::BigInt::Calc:</p> <pre><code>use bignum lib => 'Foo,Math::BigInt::Bar';</code></pre> <p>Using c<lib> warns if none of the specified libraries can be found and <a href="/pod/Math::BigInt">Math::BigInt</a> and <a href="/pod/Math::BigFloat">Math::BigFloat</a> fell back to one of the default libraries. To suppress this warning, use <code>try</code> instead:</p> <pre><code>use bignum try => 'GMP';</code></pre> <p>If you want the code to die instead of falling back, use <code>only</code> instead:</p> <pre><code>use bignum only => 'GMP';</code></pre> <p>Please see respective module documentation for further details.</p> <h2 id="Method-calls"><a id="Method"></a>Method calls</h2> <p>Since all numbers are now objects, you can use the methods that are part of the Math::BigInt and Math::BigFloat API.</p> <p>But a warning is in order. When using the following to make a copy of a number, only a shallow copy will be made.</p> <pre><code>$x = 9; $y = $x; $x = $y = 7;</code></pre> <p>Using the copy or the original with overloaded math is okay, e.g., the following work:</p> <pre><code>$x = 9; $y = $x; print $x + 1, " ", $y,"\n"; # prints 10 9</code></pre> <p>but calling any method that modifies the number directly will result in <b>both</b> the original and the copy being destroyed:</p> <pre><code>$x = 9; $y = $x; print $x->badd(1), " ", $y,"\n"; # prints 10 10 $x = 9; $y = $x; print $x->binc(1), " ", $y,"\n"; # prints 10 10 $x = 9; $y = $x; print $x->bmul(2), " ", $y,"\n"; # prints 18 18</code></pre> <p>Using methods that do not modify, but test that the contents works:</p> <pre><code>$x = 9; $y = $x; $z = 9 if $x->is_zero(); # works fine</code></pre> <p>See the documentation about the copy constructor and <code>=</code> in overload, as well as the documentation in Math::BigFloat for further details.</p> <h2 id="Methods">Methods</h2> <dl> <dt id="inf()"><a id="inf"></a>inf()</dt> <dd> <p>A shortcut to return <code>inf</code> as an object. Useful because Perl does not always handle bareword <code>inf</code> properly.</p> </dd> <dt id="NaN()"><a id="NaN"></a>NaN()</dt> <dd> <p>A shortcut to return <code>NaN</code> as an object. Useful because Perl does not always handle bareword <code>NaN</code> properly.</p> </dd> <dt id="e">e</dt> <dd> <pre><code># perl -Mbignum=e -wle 'print e'</code></pre> <p>Returns Euler's number <code>e</code>, aka exp(1) (= 2.7182818284...).</p> </dd> <dt id="PI">PI</dt> <dd> <pre><code># perl -Mbignum=PI -wle 'print PI'</code></pre> <p>Returns PI (= 3.1415926532..).</p> </dd> <dt id="bexp()"><a id="bexp"></a>bexp()</dt> <dd> <pre><code>bexp($power, $accuracy);</code></pre> <p>Returns Euler's number <code>e</code> raised to the appropriate power, to the wanted accuracy.</p> <p>Example:</p> <pre><code># perl -Mbignum=bexp -wle 'print bexp(1,80)'</code></pre> </dd> <dt id="bpi()"><a id="bpi"></a>bpi()</dt> <dd> <pre><code>bpi($accuracy);</code></pre> <p>Returns PI to the wanted accuracy.</p> <p>Example:</p> <pre><code># perl -Mbignum=bpi -wle 'print bpi(80)'</code></pre> </dd> <dt id="accuracy()"><a id="accuracy"></a>accuracy()</dt> <dd> <p>Set or get the accuracy.</p> </dd> <dt id="precision()"><a id="precision"></a>precision()</dt> <dd> <p>Set or get the precision.</p> </dd> <dt id="round_mode()"><a id="round_mode"></a>round_mode()</dt> <dd> <p>Set or get the rounding mode.</p> </dd> <dt id="div_scale()"><a id="div_scale"></a>div_scale()</dt> <dd> <p>Set or get the division scale.</p> </dd> <dt id="upgrade()"><a id="upgrade"></a>upgrade()</dt> <dd> <p>Set or get the class that the downgrade class upgrades to, if any. Set the upgrade class to <code>undef</code> to disable upgrading. See <code>/CAVEATS</code> below.</p> </dd> <dt id="downgrade()"><a id="downgrade"></a>downgrade()</dt> <dd> <p>Set or get the class that the upgrade class downgrades to, if any. Set the downgrade class to <code>undef</code> to disable upgrading. See <a href="#CAVEATS">"CAVEATS"</a> below.</p> </dd> <dt id="in_effect()"><a id="in_effect"></a>in_effect()</dt> <dd> <pre><code>use bignum; print "in effect\n" if bignum::in_effect; # true { no bignum; print "in effect\n" if bignum::in_effect; # false }</code></pre> <p>Returns true or false if <code>bignum</code> is in effect in the current scope.</p> <p>This method only works on Perl v5.9.4 or later.</p> </dd> </dl> <h1 id="CAVEATS">CAVEATS</h1> <dl> <dt id="The-upgrade()-and-downgrade()-methods"><a id="The"></a><a id="The-upgrade-and-downgrade-methods"></a>The upgrade() and downgrade() methods</dt> <dd> <p>Note that setting both the upgrade and downgrade classes at runtime with the <a href="#upgrade()">"upgrade()"</a> and <a href="#downgrade()">"downgrade()"</a> methods, might not do what you expect:</p> <pre><code># Assuming that downgrading and upgrading hasn't been modified so far, so # the downgrade and upgrade classes are Math::BigInt and Math::BigFloat, # respectively, the following sets the upgrade class to Math::BigRat, i.e., # makes Math::BigInt upgrade to Math::BigRat: bignum -> upgrade("Math::BigRat"); # The following sets the downgrade class to Math::BigInt::Lite, i.e., makes # the new upgrade class Math::BigRat downgrade to Math::BigInt::Lite bignum -> downgrade("Math::BigInt::Lite"); # Note that at this point, it is still Math::BigInt, not Math::BigInt::Lite, # that upgrades to Math::BigRat, so to get Math::BigInt::Lite to upgrade to # Math::BigRat, we need to do the following (again): bignum -> upgrade("Math::BigRat");</code></pre> <p>A simpler way to do this at runtime is to use import(),</p> <pre><code>bignum -> import(upgrade => "Math::BigRat", downgrade => "Math::BigInt::Lite");</code></pre> </dd> <dt id="Hexadecimal,-octal,-and-binary-floating-point-literals"><a id="Hexadecimal"></a><a id="Hexadecimal-octal-and-binary-floating-point-literals"></a>Hexadecimal, octal, and binary floating point literals</dt> <dd> <p>Perl (and this module) accepts hexadecimal, octal, and binary floating point literals, but use them with care with Perl versions before v5.32.0, because some versions of Perl silently give the wrong result.</p> </dd> <dt id="Operator-vs-literal-overloading"><a id="Operator"></a>Operator vs literal overloading</dt> <dd> <p><code>bigrat</code> works by overloading handling of integer and floating point literals, converting them to <a href="/pod/Math::BigRat">Math::BigRat</a> objects.</p> <p>This means that arithmetic involving only string values or string literals are performed using Perl's built-in operators.</p> <p>For example:</p> <pre><code>use bigrat; my $x = "900000000000000009"; my $y = "900000000000000007"; print $x - $y;</code></pre> <p>outputs <code>0</code> on default 32-bit builds, since <code>bignum</code> never sees the string literals. To ensure the expression is all treated as <code>Math::BigFloat</code> objects, use a literal number in the expression:</p> <pre><code>print +(0+$x) - $y;</code></pre> </dd> <dt id="Ranges">Ranges</dt> <dd> <p>Perl does not allow overloading of ranges, so you can neither safely use ranges with <code>bignum</code> endpoints, nor is the iterator variable a <code>Math::BigFloat</code>.</p> <pre><code>use 5.010; for my $i (12..13) { for my $j (20..21) { say $i ** $j; # produces a floating-point number, # not an object } }</code></pre> </dd> <dt id="in_effect()1"><a id="in_effect1"></a>in_effect()</dt> <dd> <p>This method only works on Perl v5.9.4 or later.</p> </dd> <dt id="hex()/oct()"><a id="hex1"></a><a id="hex-oct"></a>hex()/oct()</dt> <dd> <p><code>bignum</code> overrides these routines with versions that can also handle big integer values. Under Perl prior to version v5.9.4, however, this will not happen unless you specifically ask for it with the two import tags "hex" and "oct" - and then it will be global and cannot be disabled inside a scope with <code>no bignum</code>:</p> <pre><code>use bignum qw/hex oct/; print hex("0x1234567890123456"); { no bignum; print hex("0x1234567890123456"); }</code></pre> <p>The second call to hex() will warn about a non-portable constant.</p> <p>Compare this to:</p> <pre><code>use bignum; # will warn only under Perl older than v5.9.4 print hex("0x1234567890123456");</code></pre> </dd> </dl> <h1 id="EXAMPLES">EXAMPLES</h1> <p>Some cool command line examples to impress the Python crowd ;)</p> <pre><code>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->is_odd()' 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=l,GMP -le 'print 7 ** 7777'</code></pre> <h1 id="BUGS">BUGS</h1> <p>Please report any bugs or feature requests to <code>bug-bignum at rt.cpan.org</code>, or through the web interface at <a href="https://rt.cpan.org/Ticket/Create.html?Queue=bignum">https://rt.cpan.org/Ticket/Create.html?Queue=bignum</a> (requires login). We will be notified, and then you'll automatically be notified of progress on your bug as I make changes.</p> <h1 id="SUPPORT">SUPPORT</h1> <p>You can find documentation for this module with the perldoc command.</p> <pre><code>perldoc bignum</code></pre> <p>You can also look for information at:</p> <ul> <li><p>GitHub</p> <p><a href="https://github.com/pjacklam/p5-bignum">https://github.com/pjacklam/p5-bignum</a></p> </li> <li><p>RT: CPAN's request tracker</p> <p><a href="https://rt.cpan.org/Dist/Display.html?Name=bignum">https://rt.cpan.org/Dist/Display.html?Name=bignum</a></p> </li> <li><p>MetaCPAN</p> <p><a href="https://metacpan.org/release/bignum">https://metacpan.org/release/bignum</a></p> </li> <li><p>CPAN Testers Matrix</p> <p><a href="http://matrix.cpantesters.org/?dist=bignum">http://matrix.cpantesters.org/?dist=bignum</a></p> </li> </ul> <h1 id="LICENSE">LICENSE</h1> <p>This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.</p> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <p><a href="/pod/bigint">bigint</a> and <a href="/pod/bigrat">bigrat</a>.</p> <p><a href="/pod/Math::BigInt">Math::BigInt</a>, <a href="/pod/Math::BigFloat">Math::BigFloat</a>, <a href="/pod/Math::BigRat">Math::BigRat</a> and <a href="/pod/Math::Big">Math::Big</a> as well as <a href="/pod/Math::BigInt::FastCalc">Math::BigInt::FastCalc</a>, <a href="/pod/Math::BigInt::Pari">Math::BigInt::Pari</a> and <a href="/pod/Math::BigInt::GMP">Math::BigInt::GMP</a>.</p> <h1 id="AUTHORS">AUTHORS</h1> <ul> <li><p>(C) by Tels <a href="http://bloodgate.com/">http://bloodgate.com/</a> in early 2002 - 2007.</p> </li> <li><p>Maintained by Peter John Acklam <pjacklam@gmail.com>, 2014-.</p> </li> </ul></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install bignum, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm bignum</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install bignum</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>