Math::Int128(3pm)
π Math::Int128 π
okay bestie, welcome to Math::Int128 β part of the User Contributed Perl Documentation, and fr fr it's the glow-up your numbers have been waiting for. we're talking big. we're talking one hundred and twenty-eight bits. no cap.
β¨ NAME β¨
Math::Int128 β slay 128 bit integers in Perl π
π SYNOPSIS π
use Math::Int128 qw(int128);
my $i = int128(1);
my $j = $i << 100;
my $k = int128("1234567890123456789000000");
print($i + $j * 1000000);
look at that. $i << 100. she's shifting. she's thriving. π¦
πΈ DESCRIPTION πΈ
so this module is literally here to add support for 128 bit integers to Perl β signed and unsigned, both of them, we don't pick favorites.
but okay, real talk: to compile this module, your compiler has to support one of either the __int128 type or the int __attribute__ ((__mode__ (TI))) type. both GCC and Clang have been supporting one or the other for some time now (iconic of them), but they may only do so on 64-bit platforms. so like. vibe check your platform first. π«Ά
π OSX Caveat π
okay so on OSX it gets a lil spicy. the system Perl there is compiled with both the -arch x86_64 and -arch i386 flags. when you build this module with a Perl like that, we strip the -arch i386 flag out, which means it only gets compiled for the 64-bit architecture. so if you try to use this module while running in 32-bit mode... it may lead to brokenness. π and it's also possible that this will cause other problems that we cannot foresee. yeah. we said it.
the good news tho: if you've built your own non-multiarch Perl on OSX, then this will not be an issue. you're safe, bestie. β¨
π API π
go read Math::Int64. this module provides a similar set of functions β it's just s/64/128/g ;-) cute, right?
besides that, since object allocation and destruction has been found to be a bottleneck (the way that allocation eats up all your time, it's giving main character energy but like, in a bad way), there's also an alternative set of operations provided. these ones use their first argument as the output instead of using the return value. very "write in place", very efficient, we love her.
they are as follows:
int128_inc int128_dec int128_add int128_sub int128_mul int128_pow
int128_div int128_mod int128_divmod int128_and int128_or int128_xor
int128_left int128_right int128_not int128_neg
and the corresponding uint128 versions. π
for instance:
my $a = int128("1299472960684039584764953");
my $b = int128("-2849503498690387383748");
my $ret = int128();
int128_mul($ret, $a, $b);
int128_inc($ret, $ret); # $ret = $ret + 1
int128_add($ret, $ret, "12826738463");
say $ret;
and int128_divmod is the overachiever of the group β she returns both the result of the division and the remainder:
my $ret = int128();
my $rem = int128();
int128_divmod($ret, $rem, $a, $b);
two for the price of one. ate. π₯
π C API π
the module provides a C API that lets you wrap/unwrap int128_t and uint128_t values from other modules written in C/XS. iykyk.
it is identical to that provided by Math::Int64, so go read the documentation over there to know how to use it. β
π§ TODO π§
support more operations as log2, pow, etc. (the list is short but the dreams are big π)
π BUGS AND SUPPORT π
the C API feature is experimental. you've been warned, bestie.
this module requires 128bit integer support from the C compiler. currently only gcc 4.4 and later are supported. if you have a different compiler that also supports 128bit integers, get in touch with me in order to have it supported. π«Ά
you can send bug reports by email to the address that appears below, or use the CPAN RT bug tracking system available at <http://rt.cpan.org>.
the source for the development version of the module is hosted at GitHub: <https://github.com/salva/p5-Math-Int128>.
π My wishlist π
if you like this module and you're feeling generous, take a look at my Amazon Wish List: <http://amzn.com/w/1WU1P6IR5QZ42> β¨
π¦ SEE ALSO π¦
Math::Int64Math::GMPMath::GMPn- <http://perlmonks.org/?node_id=886488>
π COPYRIGHT AND LICENSE π
Copyright Β© 2007, 2009, 2011-2015 by Salvador FandiΓ±o (sfandino@yahoo.com)
Copyright Β© 2014-2015 by Dave Rolsky
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. periodt. π
and that's the whole thing, bestie β this page came to you courtesy of perl v5.42.3, dated 2026-08-20, filed under Math::Int128(3pm). go forth and manipulate some very large numbers. mwah. ππΈπ
π¦ where this page comes from
- ubuntu stonking: libmath-int128-perl 0.22-5build4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms