1Math::Int128(3)       User Contributed Perl Documentation      Math::Int128(3)
2
3
4

NAME

6       Math::Int128 - Manipulate 128 bits integers in Perl
7

SYNOPSIS

9         use Math::Int128 qw(int128);
10
11         my $i = int128(1);
12         my $j = $i << 100;
13         my $k = int128("1234567890123456789000000");
14         print($i + $j * 1000000);
15

DESCRIPTION

17       This module adds support for 128 bit integers, signed and unsigned, to
18       Perl.
19
20       In order to compile this module, your compiler must support one of
21       either the "__int128" or "int __attribute__ ((__mode__ (TI)))" types.
22       Both GCC and Clang have supported one or the other type for some time,
23       but they may only do so on 64-bit platforms.
24
25   OSX Caveat
26       On OSX, the system Perl is compiled with both the "-arch x86_64" and
27       "-arch i386" flags. When building this module with a Perl like this, we
28       strip the "-arch i386" flag out, meaning it is only compiled for the
29       64-bit architecture. Attempting to use this module while running in
30       32-bit mode may lead to brokenness. It's also possible that this will
31       cause other problems that we cannot foresee.
32
33       Note that if you have built your own non-multiarch Perl on OSX then
34       this will not be an issue.
35

API

37       See Math::Int64. This module provides a similar set of functions, just
38       "s/64/128/g" ;-)
39
40       Besides that, as object allocation and destruction has been found to be
41       a bottleneck, an alternative set of operations that use their first
42       argument as the output (instead of the return value) is also provided.
43
44       They are as follows:
45
46         int128_inc int128_dec int128_add int128_sub int128_mul int128_pow
47         int128_div int128_mod int128_divmod int128_and int128_or int128_xor
48         int128_left int128_right int128_not int128_neg
49
50       and the corresponding "uint128" versions.
51
52       For instance:
53
54         my $a = int128("1299472960684039584764953");
55         my $b = int128("-2849503498690387383748");
56         my $ret = int128();
57         int128_mul($ret, $a, $b);
58         int128_inc($ret, $ret); # $ret = $ret + 1
59         int128_add($ret, $ret, "12826738463");
60         say $ret;
61
62       "int128_divmod" returns both the result of the division and the
63       remainder:
64
65         my $ret = int128();
66         my $rem = int128();
67         int128_divmod($ret, $rem, $a, $b);
68

C API

70       The module provides a C API that allows to wrap/unwrap int128_t and
71       uint128_t values from other modules written in C/XS.
72
73       It is identical to that provided by Math::Int64 so read the
74       documentation there in order to know how to use it.
75

TODO

77       Support more operations as log2, pow, etc.
78

BUGS AND SUPPORT

80       The C API feature is experimental.
81
82       This module requires 128bit integer support from the C compiler.
83       Currently only gcc 4.4 and later are supported. If you have a different
84       compiler that also supports 128bit integers get in touch with me in
85       order to have it supported.
86
87       You can send me bug reports by email to the address that appears below
88       or use the CPAN RT bug tracking system available at
89       <http://rt.cpan.org>.
90
91       The source for the development version of the module is hosted at
92       GitHub: <https://github.com/salva/p5-Math-Int128>.
93
94   My wishlist
95       If you like this module and you're feeling generous, take a look at my
96       Amazon Wish List: <http://amzn.com/w/1WU1P6IR5QZ42>
97

SEE ALSO

99       Math::Int64, Math::GMP, Math::GMPn.
100
101       <http://perlmonks.org/?node_id=886488>.
102
104       Copyright © 2007, 2009, 2011-2015 by Salvador Fandiño
105       (sfandino@yahoo.com)
106
107       Copyright © 2014-2015 by Dave Rolsky
108
109       This library is free software; you can redistribute it and/or modify it
110       under the same terms as Perl itself, either Perl version 5.10.1 or, at
111       your option, any later version of Perl 5 you may have available.
112
113
114
115perl v5.32.1                      2021-01-27                   Math::Int128(3)
Impressum