in reply to Test modulus zero in bigint

use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump); use bigint; say STDERR "AAAA ", (1 % 0); # Should fail say STDERR "BBBB ", dump(1 % 0); if (1) {use Math::BigInt; my $a = Math::BigInt::new(1); my $b = Math::BigInt::new(0); my $c = $a->bmod($b); say STDERR "CCCC ", $c; say STDERR "DDDD ", dump($c); } # AAAA 1 # BBBB bless({ _a => undef, _p => undef, sign => "+", value => [1] }, +"Math::BigInt") # CCCC NaN # DDDD bless({ sign => NaN, value => [0] }, "Math::BigInt")

The crucial diffrence is between AAAA and CCCC.

Replies are listed 'Best First'.
Re^2: Test modulus zero in bigint
by Anonymous Monk on Sep 12, 2016 at 00:51 UTC

    my $a = Math::BigInt::new(1);

    Thats not how you create objects, you're supposed to write  my $x = Math::BigInt->new(1);

      Makes sense to me :) kinda

      perl -Mbignum -E " for $x( -1,0,1){ $y = 0; sub F{say $x % $y} F; $x +->bdiv; F;} " -1 -inf 0 NaN 1 inf

      The bdiv seems to force/convert the numeric representation to stringy value via binf/bnan

      Its a bit odd but details of division by zero are in comments https://metacpan.org/source/PJACKLAM/Math-BigInt-1.999726/lib/Math/BigInt.pm

      # Divide by zero and modulo zero. # # Division: Use the common convention that x / 0 is inf with the s +ame sign # as x, except when x = 0, where we return NaN. This is also what +earlier # versions did. # # Modulo: In modular arithmetic, the congruence relation z = x (mo +d y) # means that there is some integer k such that z - x = k y. If y = + 0, we # get z - x = 0 or z = x. This is also what earlier versions did, +except # that 0 % 0 returned NaN. # # inf / 0 = inf inf % 0 = inf # 5 / 0 = inf 5 % 0 = 5 # 0 / 0 = NaN 0 % 0 = 0 # -5 / 0 = -inf -5 % 0 = -5 # -inf / 0 = -inf -inf % 0 = -inf