Giter Club home page Giter Club logo

math-gmpq's People

Contributors

sisyphus avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

math-gmpq's Issues

Rmpq_set_si() with 64-bit signed integers

Hi,

There seems to be an imbalance between Rmpq_set_ui() and Rmpq_set_si() in the way that Rmpq_set_si() does not seem to work with very small 64-bit signed integers.

Here is some code which illustrates the issue:

use 5.010;
use strict;
use warnings;

use Math::GMPq qw(:mpq);

sub ui_rat {
    my ($num, $den) = @_;
    my $q = Rmpq_init();
    Rmpq_set_ui($q, $num, $den);
    $q;
}

sub si_rat {
    my ($num, $den) = @_;
    my $q = Rmpq_init();
    Rmpq_set_si($q, $num, $den);
    $q;
}

my $max_ui = ~0;
my $min_si = -(~0 >> 1) - 1;

say "MAX_UI: $max_ui";    # MAX_UI: 18446744073709551615
say "MIN_SI: $min_si";    # MIN_SI: -9223372036854775808

say '-' x 28;

say "UI_RAT: ", ui_rat($max_ui, 1);    # UI_RAT: 18446744073709551615
say "SI_RAT: ", si_rat($min_si, 1);    # SI_RAT: 0

say '-' x 28;

say "SI_RAT with -2^31-1: ", si_rat(-2**31 - 1, 1);    # SI_RAT with -2^31-1: 2147483647
say "SI_RAT with -2^31:  ",  si_rat(-2**31,     1);    # SI_RAT with -2^31:  -2147483648

The output is:

MAX_UI: 18446744073709551615
MIN_SI: -9223372036854775808
----------------------------
UI_RAT: 18446744073709551615
SI_RAT: 0                                        # <-- incorrect
----------------------------
SI_RAT with -2^31-1: 2147483647                  # <-- incorrect
SI_RAT with -2^31:  -2147483648

As shown above, the minimum signed value accepted by Rmpq_set_si(), is -2^31.

Issue in Rmpq_z_div(r, z, q) when z=0

Hi Rob,

There is a minor issue in Rmpq_z_div(r, z, q) when z holds the value 0.

use strict;
use warnings;

use Math::GMPz;
use Math::GMPq;

my $r = Math::GMPq->new('0');
my $z = Math::GMPz->new('0');
my $q = Math::GMPq->new('42');

Math::GMPq::Rmpq_z_div($r, $z, $q);

print $r;                        # should print '0'

Output:

[1]    31405 floating point exception (core dumped)  perl x.pl

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.