Giter Club home page Giter Club logo

p5-math-int128's Introduction

NAME

Math::Int128 - Manipulate 128 bits 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);

DESCRIPTION

This module adds support for 128 bit integers, signed and unsigned, to Perl.

In order to compile this module, your compiler must support one of either the __int128 or int __attribute__ ((__mode__ (TI))) 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.

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.

Note that if you have built your own non-multiarch Perl on OSX then this will not be an issue.

API

See Math::Int64. This module provides a similar set of functions, just s/64/128/g ;-)

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.

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;

int128_divmod returns both the result of the division and the remainder:

my $ret = int128();
my $rem = int128();
int128_divmod($ret, $rem, $a, $b);

C API

The module provides a C API that allows to wrap/unwrap int128_t and uint128_t values from other modules written in C/XS.

It is identical to that provided by Math::Int64 so read the documentation there in order to know how to use it.

TODO

Support more operations as log2, pow, etc.

BUGS AND SUPPORT

The C API feature is experimental.

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 me 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::Int64, Math::GMP, Math::GMPn.

http://perlmonks.org/?node_id=886488.

COPYRIGHT AND LICENSE

Copyright © 2007, 2009, 2011-2015 by Salvador Fandiño ([email protected])

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.

p5-math-int128's People

Contributors

autarch avatar fschlich avatar salva avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

p5-math-int128's Issues

Version 0.21 is not tagged in the rep

@salva - how did you do the last release? Running dzil release should have done this automatically.

Maybe try running git push --tags from your local copy of the repo just in case the tag is there but didn't get pushed for some reason.

utf8 "\x80" does not map to Unicode

Hi Dave,

When I run dzil release I get the following error:

Do you want to continue the release process? [y/N]: y
PAUSE username:  : SALVA
PAUSE password:  : 
[@DROLSKY/CheckPrereqsIndexed] all prereqs appear to be indexed
[@DROLSKY/Git::CheckFor::CorrectBranch] Current branch (master) and release branch match (master)
Could not decode UTF-8 dll.base; filename set by GatherDir (Dist::Zilla::Plugin::GatherDir line 215); encoded_content added by @DROLSKY/GatherDir (Dist::Zilla::Plugin::GatherDir line 216); error was: utf8 "\x80" does not map to Unicode at /usr/lib/x86_64-linux-gnu/perl/5.20/Encode.pm line 175.
; maybe you need the [Encoding] plugin to specify an encoding at /usr/local/share/perl/5.20.1/Dist/Zilla/Role/File.pm line 153.
    Dist::Zilla::Role::File::_throw(Dist::Zilla::File::OnDisk=HASH(0x6f3a498), "decode UTF-8", "utf8 \"\\x80\" does not map to Unicode at /usr/lib/x86_64-linux-"...) called at /usr/local/share/perl/5.20.1/Dist/Zilla/Role/File.pm line 145
    Dist::Zilla::Role::File::catch {...} ("utf8 \"\\x80\" does not map to Unicode at /usr/lib/x86_64-linux-"...) called at /usr/share/perl5/Try/Tiny.pm line 104
    Try::Tiny::try(CODE(0xda811f8), Try::Tiny::Catch=REF(0xda81390)) called at /usr/local/share/perl/5.20.1/Dist/Zilla/Role/File.pm line 145
    Dist::Zilla::Role::File::_decode(Dist::Zilla::File::OnDisk=HASH(0x6f3a498), "\x{18}\x{80}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}\x{10}\x{0}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}8\x{80}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}0\x{80}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}\x{0}\x{90}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}\x{8}\x{90}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}\x{10}\x{90}\x{1}\x{0}\x{0}\x{0}\x{0}\x{0}\x{18}\x{90}\x{1}\x{0}\x{0}"...) called at /usr/local/share/perl/5.20.1/Dist/Zilla/Role/MutableFile.pm line 54
    Dist::Zilla::Role::MutableFile::content(Dist::Zilla::File::OnDisk=HASH(0x6f3a498)) called at /usr/local/share/perl/5.20.1/Dist/Zilla/Plugin/Git/CheckFor/MergeConflicts.pm line 70
    Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts::before_release(Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts=HASH(0x720f5e8), Path::Class::File=HASH(0x8fa6c18)) called at /usr/local/share/perl/5.20.1/Dist/Zilla/Dist/Builder.pm line 554
    Dist::Zilla::Dist::Builder::release(Dist::Zilla::Dist::Builder=HASH(0x4547668)) called at /usr/local/share/perl/5.20.1/Dist/Zilla/App/Command/release.pm line 34
    Dist::Zilla::App::Command::release::execute(Dist::Zilla::App::Command::release=HASH(0x249a678), Getopt::Long::Descriptive::Opts::__OPT__::2=HASH(0x25e9748), ARRAY(0x21e2f40)) called at /usr/share/perl5/App/Cmd.pm line 282
    App::Cmd::execute_command(Dist::Zilla::App=HASH(0x1df6948), Dist::Zilla::App::Command::release=HASH(0x249a678), Getopt::Long::Descriptive::Opts::__OPT__::2=HASH(0x25e9748)) called at /usr/share/perl5/App/Cmd.pm line 210
    App::Cmd::run("Dist::Zilla::App") called at /usr/local/bin/dzil line 15

Any idea about what could be the cause of the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.