math-gmpz's Introduction
This module wraps all of the 'mpz' (integer) functions that the Gnu MP (GMP) library provides. Requires gmp-4.2.0 or later. You therefore need the GMP library installed on your computer. See: https://gmplib.org/ To build this module you need perl 5.6.0 or later. I'm not sure of all the requirements to get it to build with earlier versions of perl, but it's definite that the XS code relating to operator overloading will not compile with perl versions prior to 5.6. No OO interface - just plain access to GMP's integer functions. Build in the usual way: perl Makefile.PL make make test make install When building this module, the GMP library will need to be accessible. If it's not in a location where your compiler finds it by default, then instead of running 'perl Makefile.PL', you'll need to run: perl Makefile.PL INC="-I/path/to/gmp_include" LIBS="-L/path/to/gmp_lib -lgmp" ============== 64-bit support ============== If your perl's Config reports that 'ivsize' is greater than or equal to 8 && 'ivtype' is not 'long', then Math::GMPz will, by default, be built to enable you to use the 64-bit long long int values with the new() function and the overloaded operators. Similarly, if your perl's Config reports that 'nvsize' > 8, then Math::GMPz will, by default, be built to enable you to use the larger precision values (be they either 'long double' or '__float128' with the new() function and the overloaded operators. I am contactable by email at sisyphus at(@) cpan dot (.) org. ========== MAC OS X ========== I don't test on Macs ... and I don't know if the following advice is still relevant: If you have MacPorts installed, you may need to install gmp +universal for the bindings to work. After installing you'll need to run: perl Makefile.PL INC="-I/opt/local/include" LIBS="-L/opt/local/lib -lgmp" =============================== MS WINDOWS (Visual Studio 2019) =============================== I don't know how to build the gmp library using Visual Studio 2019, so when building this module with Visual Studio 2019 I build against a gmp library that was built using MinGW-w64. Building with Visual Studio 2019 against a *dynamic* gmp library that was built using a MinGW-w64 compiler is not recommended, as strange results can then arise when calling gmp functions that take a FILE* argument. If building with Visual Studio 2019 against a static gmp library that was built using a MinGW-w64 compiler I first make a copy of the gmp library (libgmp.a) along with copies of the following MinGW-w64 library files: libgcc.a libmingwex.a libmingw32.a For each of the 4 copied files, I leave the filename unchanged (though the "lib" at the begining of the name is optional), and change the file extension to ".lib". In making those copies, I've left them in the same directory as the original, but I assume (untested) that the copies could be moved to any location of your choice. Then build this module by cd'ing to the top level Math::GMPz source folder and running: perl Makefile.PL INC="-IC:/path/to/gmp_header" LIBS="-LC:/path/to/libgcc -lgcc -LC:/path/to/standard_libs -lmingwex -lmingw32 -LC:/path/to/libgmp -lgmp" nmake test nmake install NOTES: 1) The given example "perl Makefile.PL ..." command assumes that libmingwex and libmingw32 libraries are in the same location; 2) The same method can be used to build Math::GMP using VS 2019.
math-gmpz's People
Forkers
chrestomancimath-gmpz's Issues
Math::GMPz->new() with a large number tested in numerical context
Hi Rob,
I just discovered a strange case where a very large number (stored as a string) is tested in a numerical context, fails when this number is later provided as argument to Math::GMPz->new()
.
use 5.010;
use strict;
use warnings;
use Math::GMPz;
my $n = '1848210397825850670380148517702559371400899745254512521925707445580334710601412527675708297932857843901388104766898429433126419139462696524583464983724651631481888473364151368736236317783587518465017087145416734026424615690611620116380982484120857688483676576094865930188367141388795454378671343386258291687641';
if ($n > ~0) {
say Math::GMPz->new("$n"); # this is OK
say Math::GMPz->new($n); # this fails
}
Output:
1848210397825850670380148517702559371400899745254512521925707445580334710601412527675708297932857843901388104766898429433126419139462696524583464983724651631481888473364151368736236317783587518465017087145416734026424615690611620116380982484120857688483676576094865930188367141388795454378671343386258291687641
[1] 17383 abort (core dumped) perl x.pl
Output of perl -V
:
Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
Platform:
osname=linux, osvers=4.7.3-1-arch, archname=x86_64-linux-thread-multi
uname='linux flo-64 4.7.3-1-arch #1 smp preempt wed sep 7 17:57:38 cest 2016 x86_64 gnulinux '
config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Dcccdlflags='-fPIC' -Dlddlflags=-shared -Wl,-O1,--sort-common,--as-needed,-z,relro -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion='', gccversion='6.1.1 20160802', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/include-fixed /usr/lib /lib/../lib /usr/lib/../lib /lib /lib64 /usr/lib64
libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
libc=libc-2.24.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.24'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE'
cccdlflags='-fPIC', lddlflags='-shared -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT
USE_ITHREADS USE_LARGE_FILES USE_LOCALE
USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO
USE_PERL_ATOF USE_REENTRANT_API
Built under linux
Compiled at Sep 8 2016 13:46:22
@INC:
/usr/lib/perl5/site_perl
/usr/share/perl5/site_perl
/usr/lib/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib/perl5/core_perl
/usr/share/perl5/core_perl
.
Version of Math::GMPz:
$ perl -MMath::GMPz -E 'say $Math::GMPz::VERSION'
0.43
This issue also seems to affect Math::GMPq, Math::GMPf, Math::MPFR and Math::MPC.
Wrong args supplied to mpz_urandomm function
Hello!
The latest version seems to have introduced an issue in the Rmpz_urandomm
function, as illustrated in the following code:
use 5.010;
use Math::GMPz;
package Number {
sub new {
my ($class, $n) = @_;
bless \$n, $class;
}
sub add {
my ($self, $n) = @_;
Number->new($$self + $$n);
}
my $srand = srand();
my $state = Math::GMPz::zgmp_randinit_mt();
Math::GMPz::zgmp_randseed_ui($state, $srand);
sub irand {
my ($self) = @_;
my $x = Math::GMPz->new($$self);
Math::GMPz::Rmpz_urandomm($x, $state, $x, 1);
say "x = $x";
return Number->new($x);
}
}
my $x = Number->new(42);
say ${$x->irand}; # this works
say ${$x->add($x->irand)}; # this fails
Output with perl-5.38.0:
x = 41
41
Wrong args supplied to mpz_urandomm function at rand.pl line 23
In earlier versions, the above code worked correctly: see tio.run output
0.47 build failure with older gmp library
There appears to be a mismatched parenthesis in 0.47 that is encountered when using an older gmp library.
GMPz.xs: In function 'overload_not_equiv':
GMPz.xs:3930: error: too few arguments to function 'my_cmp_z'
GMPz.xs:3930: error: expected ';' before ')' token
GMPz.xs:3930: error: expected statement before ')' token
make: *** [GMPz.o] Error 1
if(strEQ(h, "Math::GMPq")) {
#if __GNU_MP_RELEASE < 60099
ret = my_cmp_z(INT2PTR(mpq_t *, SvIVX(SvRV(b)))), a);
if(ret != 0) return newSViv(1);
return newSViv(0);
#else
ret = mpq_cmp_z(*(INT2PTR(mpq_t *, SvIVX(SvRV(b)))), *a);
if(ret != 0) return newSViv(1);
return newSViv(0);
#endif
}
Rmpz_rootrem() is not documented.
The function Rmpz_rootrem()
seems to not be documented in Math::GMPz.
Documentation: https://gmplib.org/manual/Integer-Roots.html:
Issue in Math::GMPz::overload_pow()
Hi,
There seems to be a minor issue in Math::GMPz::overload_pow() when the power is a Math::GMPz object and the base is a Perl integer.
The following code illustrates the problem:
use 5.014;
use warnings;
use Math::GMPz;
my $p = Math::GMPz->new(5);
say $p**3; # this works
say 3**$p; # this fails
Output:
125
Invalid third argument (&PL_sv_yes) supplied to Math::GMPz::overload_pow function at z.pl line 10.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.