.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Math::Int128 3pm" .TH Math::Int128 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Math::Int128 \- Manipulate 128 bits integers in Perl .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Math::Int128 qw(int128); \& \& my $i = int128(1); \& my $j = $i << 100; \& my $k = int128("1234567890123456789000000"); \& print($i + $j * 1000000); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module adds support for 128 bit integers, signed and unsigned, to Perl. .PP In order to compile this module, your compiler must support one of either the \&\f(CW\*(C`_\|_int128\*(C'\fR or \f(CW\*(C`int _\|_attribute_\|_ ((_\|_mode_\|_ (TI)))\*(C'\fR types. Both GCC and Clang have supported one or the other type for some time, but they may only do so on 64\-bit platforms. .SS "OSX Caveat" .IX Subsection "OSX Caveat" On OSX, the system Perl is compiled with both the "\-arch x86_64" and "\-arch i386" flags. When building this module with a Perl like this, we strip the "\-arch i386" flag out, meaning it is only compiled for the 64\-bit architecture. Attempting to use this module while running in 32\-bit mode may lead to brokenness. It's also possible that this will cause other problems that we cannot foresee. .PP Note that if you have built your own non-multiarch Perl on OSX then this will not be an issue. .SH API .IX Header "API" See Math::Int64. This module provides a similar set of functions, just \f(CW\*(C`s/64/128/g\*(C'\fR ;\-) .PP Besides that, as object allocation and destruction has been found to be a bottleneck, an alternative set of operations that use their first argument as the output (instead of the return value) is also provided. .PP They are as follows: .PP .Vb 3 \& 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 .Ve .PP and the corresponding \f(CW\*(C`uint128\*(C'\fR versions. .PP For instance: .PP .Vb 7 \& 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; .Ve .PP \&\f(CW\*(C`int128_divmod\*(C'\fR returns both the result of the division and the remainder: .PP .Vb 3 \& my $ret = int128(); \& my $rem = int128(); \& int128_divmod($ret, $rem, $a, $b); .Ve .SH "C API" .IX Header "C API" The module provides a C API that allows one to wrap/unwrap int128_t and uint128_t values from other modules written in C/XS. .PP It is identical to that provided by Math::Int64 so read the documentation there in order to know how to use it. .SH TODO .IX Header "TODO" Support more operations as log2, pow, etc. .SH "BUGS AND SUPPORT" .IX Header "BUGS AND SUPPORT" The C API feature is experimental. .PP 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. .PP You can send me bug reports by email to the address that appears below or use the CPAN RT bug tracking system available at . .PP The source for the development version of the module is hosted at GitHub: . .SS "My wishlist" .IX Subsection "My wishlist" If you like this module and you're feeling generous, take a look at my Amazon Wish List: .SH "SEE ALSO" .IX Header "SEE ALSO" Math::Int64, Math::GMP, Math::GMPn. .PP . .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright © 2007, 2009, 2011\-2015 by Salvador Fandiño (sfandino@yahoo.com) .PP Copyright © 2014\-2015 by Dave Rolsky .PP 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.