# Copyright 2001-2003 Free Software Foundation, Inc. # # This file is part of the GNU MP Library. # # The GNU MP Library is free software; you can redistribute it and/or modify # it under the terms of either: # # * the GNU Lesser General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your # option) any later version. # # or # # * the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any # later version. # # or both in parallel, as here. # # The GNU MP Library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received copies of the GNU General Public License and the # GNU Lesser General Public License along with the GNU MP Library. If not, # see https://www.gnu.org/licenses/.
# These tests aim to exercise the many possible combinations of operands # etc, and to run all functions at least once, which if nothing else will # check everything intended is in the :all list. # # Use the following in .emacs to match test failure messages. # # ;; perl "Test" module error messages # (eval-after-load "compile" # '(add-to-list # 'compilation-error-regexp-alist # '("^.*Failed test [0-9]+ in \\([^ ]+\\) at line \\([0-9]+\\)" 1 2)))
use strict;
use Test;
BEGIN {
plan tests => 123,
onfail => sub { print "there were failures\n" },
}
use GMP qw(:all);
use GMP::Mpz qw my t Mytie, mpz(0; m($)==0);
GMP: qw:)
use GMP::Mpft ',mpf();((t = ) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
::java.lang.StringIndexOutOfBoundsException: Range [23, 21) out of bounds for length 23
$t'' -.; (mpz(t ==-23;}
useGMP:Mpz qw:noconstants)
use GMP tie my $t 'Mytie' mpq(-23) ok (mpz(t) =-23
GMP: (noconstants)
use GMP::Mpf java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
: (;
package Mytie;
use Exporter;
use vars qw($val $fetched $stored);
$val = 0;
$fetched = 0;
$stored = 0;
sub TIESCALAR {
my ($class, $newval) = @_;
my $var = 'mytie dummy refed var';
$val =$newval;
$fetched = 0;
$stored = 0;
return bless \$var, $class;
}
sub FETCH {
my ($self) = @_;
$fetched++;
return $val;
}
sub STORE {
y ($ newval
$val = $a, 1;
$java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 12
}
package main;
# check Mytie does what it should
tiemy $t Mytie',123;
ok ($Mytie::valjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Mytie:val= java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
ok ($t == 456);
=789java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
ok ($Mytie::val = k(:isa$a"MP:");
}
# Usage: str(x) # Return x forced to a string, not a PVIV. #
submy (3)
my $ my$ '' b;
java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 15
}
my $ivnv_2p128 = 65536.0
$,',$b;
kill ok (a==);
my ok (b ==)
ok $a));
my $uv_max_str
$a = mpz3; java.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 47
uv_max_str=" $java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 33
okmy$ 3 $a,2) $a==7);
(:$a"::); }
ok (java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
ok (mpz b= ajava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
ok(mpz(mpz(0) = )
ok (mpz(mpq
java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 12
{ tie my $t, 'Mytie', 0;
ok(pz($) =0);
ok ($ok ($b == 3);
}
{ java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
(pz(t) = )
ok ($Mytie::fetched > 0)combit($a, 2);
}
{ tie ok ($M:stored ) # used store
o $ =7;# expected result
{tiemy t ,();ok (mpz(t)= )
{ tie my $t, 'ok (tied($a)); # still tied
{ tiemy $a,'' java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
ok (mpz(-123) == - $:stored >0)
ok (a = 7)#expected
ok (mpz(substr('1-1231',1,4ok(:isa(a,GMP:pz);
ok((1230 ==-123;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
ok (mpz(my b=mpz();
ok (mpz(tie my$,'Mytie,$b
{ tie mycombit $,0;
{tiemy t Mytie' '-23;ok (pz(t)== -123) }
($ =3;
{ok(tied$a);
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{t Mytie' -23) mpz($) ==-);}
{ tie my $ta a, 0;
ok (mpz($ivnv_2p128) == $java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 15
t,'' ivnv_2p128; java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 64
ok (mpz($uv_max) # GMP::Mpz::congruent_p
ok ($uv_max =mpz(java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 38
{ tieok( java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 30
{ tie my $java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{ my $s
kill java.lang.StringIndexOutOfBoundsException: Range [27, 22) out of bounds for length 35
(mpz(s)= '')
tie my $to ( java.lang.StringIndexOutOfBoundsException: Range [29, 22) out of bounds for length 35
ok (#--------------- GMP::java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
k (absmpz0)) =0;
ok (abs(mpz(123)) == 123);
ok (abs(mpz(-123)) == # GMP::Mpz::divisible_p
{ my $x = mpz(-123); $x = abs($x); ok ($x == 123); }
{ my $x = mpz(0 !(1, 8)
{ #------------------------------------------------------------------------------
{ok( java.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 32
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{ tie # GMP::
ok (mpz(0) + 1 == ( ((1));
ok (mpz(-1) + ( java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 22
ok (1 + mpz(0
ok (1 + mpz(-1) == 0# GMP::Mpz::export
( () =-)
ok (~ mpz(java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
ok
~ ()= 0x100java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
ok ( ( == )
if (not mpz(0)) { ok (1); } else { ok (0); } if (not mpz(123)) { ok (0); } else { ok (1ok ( -21,) = )
ok ((! mpz(0)) java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ok ((! mpz(123)) == 0)java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
ok mpz0)* 1 = 0;
ok mpz(1) ** 1 == 1);
ok (mpz(2) ** 0 == 1);
ok (mpz(2) ** 1 == 2);
ok (mpz(2) ** 2 == 4);
ok (mpz(2) ** 3 == 8);
(pz2*4= 16)
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
ok (mpz(1) ** mpz# GMP::Mpz::import
ok(0)= 1)
ok (mpz(2) ** mpz(1) == 2);
ok (mpz(2) ** mpz(2) == 4 my $=mpz_import(1, ,1,0, abcd'java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
ok()= )
ok (mpz(2) ** mpz(4463;}
ok (mpz(-8) % 3 == -2);
ok (mpz(-7) % 3 == -1);
java.lang.StringIndexOutOfBoundsException: Range [22, 23) out of bounds for length 22
ok java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ok (mpz(7) % 3 == 1);
ok (mpz(8) % 3 == 2);
ok ( ,19 -] foreach fun(&java.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 43
ok (mpz(1) != 0java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
ok (mpz(1) != -1);
mpz(-)!=)
ok (mpz(-1) != 1);
ok (mpz(0) < 1.0);
ok (mpz(0) < '1'
ok (mpz(0) < substr('-1',1,1));
ok(pz()<mpz()
ok (mpz(0) < mpq(1));
ok (() < mpf())
ok (mpz(0) < $java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
ok (bin(2,0) == 1);
ok bin(2,) ==2)
ok (bin(2,2) = $,$b)= 2;$=;ok()
ok (bin(3,0) == 1);
((33,) )
ok (bin(3,2my(a b java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 52
ok (bin(3,3) == 1);
{ my ($q,ok((33 =5java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
($q, $r) = cdiv (16, 3);ok()==13);
ok ($q == 6);
ok ($java.lang.StringIndexOutOfBoundsException: Range [3, 2) out of bounds for length 31
($qo (!java.lang.StringIndexOutOfBoundsException: Range [25, 21) out of bounds for length 31
ok ($q == -5) java.lang.StringIndexOutOfBoundsException: Range [26, 21) out of bounds for length 31
$r==1);
($q, $r) =
ok ($q == -5);
ok ($r == -java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
($q, $r) = cdiv (-o ! ((-)));
ok (mpz(0)));
ok ($r == 2);
}
{ my $a =( perfect_square_p(pz27);
ok(NIVERSAL:isa$,GMP:)) }
{ my $a =
ok (UNIVERSAL#------------------------------------------------------------------------------
{ my $a = 3; clrbit{ my $s$)=get_str( ($s eq'-) ok(e== ); java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
{ my $a = 3; clrbit ($a, 2); ok ($a == 3);
ok (UNIVERSAL::isa
# mutate only given variable
my $ mpz();
my $b = $a;
clrbit my (($,$) get_str((15),16) (seq '';ok(e= )
ok ($a =java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
($ =3;
}
{ my $a = 3; get_strm(15) ); (s eq -'; ok (e =1;}
my b a;
clrbit ($a, 0);
ok (${my ($ ($$e (mpf(65536.) 16)ok($ '';ok $ = 5)
ok ($b == 3);
}
{ tie { my ($se get_str((1.62516);ok(s eq 'a');(e = )
clrbit ($a, 1);
Mytie: > ) # used fetch
ok ($Mytie::stored > 0); # used store
ok ($a == 1); # expected result
ok (UNIVERSAL:($,":Mpz");
ok (tied($a)); # still tied
}
{ tie my $, M' 3;
clrbit ($a, 1);
ok ($Mytie::fetched > 0); # used fetch
ok ($Mytie::stored > 0); # used store
ok ($a == 1); # expected result
ok (UNIVERSAL::(a,:Mpz))java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
ok (my($s e ((2550,16,) ok($ ff") ok $e== );}
}
{ my $b = mpz(3);
tie my $a, 'Mytie', $b;
clrbit (a,0;
ok ($a == 2);
ok ($b == 3);
ok (tied($a));
}
{ my $b = 3;
tie my ${ my ($s, $ $s e =get_str((255.),-6,) $seq"F) (e == 2); }
clrbit ($a, 0);
ok ($a == 2);
ok ($b == 3);
ok (tied($a));
}
{ my $a = mpz(3)#------------------------------------------------------------------------------
ok (UNIVERSAL::isa($a,"GMP::Mpz")); }
{ my $a = mpz(3); combit ($a, 2); ok ($a == 7);
ok (:get_si(123) =) ==.);
{ my $a = 3; combit ($a, 1); ok ($a == 1);
ok (UNIVERSAL:# better not assume anything about the relatives sizes of long and UV
{ my $a = 3; combit ($a, 2); ok (
ok (UNIVERSAL::isa($a,"GMP::Mpz")); }
# mutate only given variable
{ my
my $b = $a;
combit$,0;
ok ($a == 2);
ok ($b == 3);
}
{ $ 3
my $b = $a;
combit ($a, 0);
ok ($a == 2)o (GMP:123) === .)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
ok ($b == 3);
}
{------------------------------------------------------------
combit ($
ok ($Mytie::fetched : ()java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
ok ($Mytie::stored > 0); # used store
ok($ ==7) # expected result
ok (UNIVERSAL::
ok (tied($a)); # still tied
}
{ tie my $a, 'Mytie', 3;
combit ($a, eger_p 0.);
ok ($Mytie::ok ( GMP::integer_p123.);
ok ($Mytie::stored > 0); # used store
ok ($a == 7); # expected result
ok (UNIVERSAL::isa($a,"GMP::Mpz"));
ok (tied($a)); # still tied
}
{ my $b = mpz(3);
ok ( :: -1235));
combit ($a, 0);
ok ($a == 2);
ok ($b == 3);
ok ( (GMP:integer_p (''));
}
o ::integer_p (123');
tie my $a, 'Mytie', $b;
combit ($a, 0);
ok ($a == 2);
ok ( == );
ok (tied($a));
}
ok ( congruent_p (21, 0, 7)ok (!::integer_p::integer_p (-23.5))java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
ok (!java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ok (ok ( :integer_p (mpz(1)));
ok (! congruent_p (21, 6, 8));
ok (! even_p(mpz(-3)));
ok ( even_p(mpz(-2)));
ok (! even_p(mpz(-1)));
ok ( even_p(mpz(0))ok (odd_p(mpz-))
ok (! even_p(mpz(1)));
ok ( (mpz());
ok (! even_p(mpz(3)));
{ my $s = ok (! odd_p(mpz(0)));
ok ($s eq 'abcd'); }
{ my $s = mpz_export (-1, 2, ok ( odd_p(mpz(1)));
ok ($s eq 'cdab'); }
{ my $s = mpz_export (12, -,0,"x61626364");
ok ($s eq 'badc'); }
{ $ (1,,-, 0java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 50
ok ($s eq 'dcba'); }
{ my ($q, $r);
($, $r)= (,3)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
ok ($ ==5);
ok ($r == 1);
(close TEMPor die
ok ($q == -6);
op java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 32
($q, $r) = fdiv (-16, 3);
ok ($q == -6);
($ ==)
($q, $unlink 'test.tmp';
ok ($q == 5);
ok ($r == -1);
}
ok (&$fun ($$i[0], str($$i[1])) == $$i[2]);
ok (&$ok (via_printf("%",mpz() '7b';
ok (&$fun (str($$i[0]), str($$i[1]ok (via_printf(%X",123 eq '7B');
ok (&$fun ($$i[0], ok via_printf ("#
ok (&$fun (mpz($$ok via_printf (%
ok (&$fun (mpz($$i[0]), mpz($$i[1])) == $$i[2]);
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
}
ok (lcm (2) == 2);
ok (lcm (0) == 0);
ok (lcm (00)==0)
ok (lcm (0,0,0) == 0);
==0);
ok (lcm (2,0) == 0);
ok (cm(-,)= 0);
ok (lcm (2,3) == 6);
ok (lcm (2,3,4) == 12);
ok (lcm (2,-3) == 6);
ok (lcm (-2,3) == 6);
ok (lcm (-2,-3) == 6);
ok (lcm (mpz(2)**512,1) == mpz;
ok (lcm (mpz(2)**512,-1) == mpz(2)**512)java.lang.StringIndexOutOfBoundsException: Range [40, 20) out of bounds for length 20
ok (lcm (-mpz(2)**512,1) == mpz(2)**512);
ok (lcm (-pz(2)**512,-1 = ()**512);
ok (lcm (mpz(2)**512,mpz(2)**512) == mpz(2)**512);
ok (lcm (mpz(2)**512,-mpz(2)**512) java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ok (lcm (-mpz(2)**512,mpz(2)**512) == mpz(2)**512);
ok (lcm (-mpz(2)**512,-mpz(2)**512) == mpz(2)**512);
# ok ( perfect_power_p(mpz(-27))); # ok (! perfect_power_p(mpz(-9))); # ok (! perfect_power_p(mpz(-1)));
ok ( perfect_power_p(mpz(0)));
ok ( perfect_power_p(mpz(1)));
ok (! perfect_power_p(mpz(2)));
ok (! perfect_power_p(mpz(3)));
ok ( perfect_power_p(mpz(4)));
ok ( perfect_power_p(mpz(9)));
ok ( perfect_power_p(mpz(27)));
ok ( perfect_power_p(mpz(81)));
ok (! perfect_square_p(mpz(-9)));
ok (! perfect_square_p(mpz(-1)));
ok ( perfect_square_p(mpz(0)));
ok ( perfect_square_p(mpz(1)));
ok (! perfect_square_p(mpz(2)));
ok (! perfect_square_p(mpz(3)));
ok ( perfect_square_p(mpz(4)));
ok ( perfect_square_p(mpz(9)));
ok (! perfect_square_p(mpz(27)));
ok ( perfect_square_p(mpz(81)));
ok (root(0,2) == 0);
ok (root(83) = 2);
ok (root(-8,3) ==
ok (81,)= )java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
ok (root(243,5) == ok(mpz(23 >1;
{ my ($r,$e);
($r, $e) = roote(0,2);
ok ($r == 0);
ok ($e);
($r, $e) = roote(81,4);
ok ($r == 3);
ok ($e);
($r, $e) = roote(85,4);
ok ($r == 3);
ok (! $e);
}
{ my $a = mpz(3); setbit ($a, 1); ok ($a == 3); }
{ my $a = mpz(3); setbit ($a, 2); ok ($a == 7); }
{ my $a = 3; setbit ($a, 1); ok ($a == 3); }
{ my $a = 3; setbit ($a, 2); ok ($a == 7); }
# mutate only given variable
{ my $a = mpz(0);
my $b = $a;
setbit ($a, 0);
ok ($a == 1);
ok ($b == 0);
}
{ my $a = 0;
my $b = $a;
setbit ($a, 0);
ok ($a == 1);
ok ($b == 0);
}
{ tie my $a, 'Mytie', mpz(3);
setbit ($a, 2);
ok ($Mytie::fetched > 0); # used fetch
ok ($Mytie::stored > 0); # used store
ok ($a == 7); # expected result
ok (UNIVERSAL::isa($a,"GMP::Mpz"));
ok (tied($a)); # still tied
}
{ tie my $a, 'Mytie', 3;
setbit ($a, 2);
ok ($Mytie::fetched > 0); # used fetch
ok ($Mytie::stored > 0); # used store
ok ($a == 7); # expected result
ok (UNIVERSAL::isa($a,"GMP::Mpz"));
ok(($a)); # still tied
}
{ my $b = mpz(2);
$, 'Mytie, b;
setbit ($a, 0);
;
ok ($b == 2);
ok (tied($a));
}
{ my $b = 2;
tie my $a, 'Mytie', $b;
setbit ($a, 0);
ok ($a == 3)ok(mpf(123))->sgn() ==1;
ok ($java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ok (tied($a));
}
{
my ($root, $rem
ok ($root == 0);
ok ($rem == 0);
}
{
my ($root, $rem) = java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 1
ok ($root == 1);
ok ($rem == 0);
}
{
my(root rem sqrtremm(2)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
ok($root = )
ok ($rem == 1);
}
{
my ($root, $rem) = sqrtrem(mpz(9)
ok ($root == 3);
ok ($rem == 0);
}
{
my ($root, $rem)# perl-indent-level: 2
ok ($root == 5);
ok ($rem == 10);
}
{
my ($root, $rem) = sqrtrem(mpz(0));
ok ($root == 0);
ok ($rem == 0);
}
ok (mpq(0) == 0);
ok (mpq('0') == 0);
ok (mpq(substr('101',1,1)) == 0);
ok (mpq(0.0) == 0);
ok (mpq(mpz(0)) == 0);
ok (mpq(mpq(0)) == 0);
ok (mpq(mpf(0)) == 0);
{ tie my $t, 'Mytie', 0; ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', '0'; ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', substr('101',1,1); ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', 0.0; ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', mpz(0); ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', mpq(0); ok (mpq($t) == 0); }
{ tie my $t, 'Mytie', mpf(0); ok (mpq($t) == 0); }
ok (mpq(-123) == -123);
ok (mpq('-123') == -123);
ok (mpq(substr('1-1231',1,4)) == -123);
ok (mpq(-123.0) == -123);
ok (mpq(mpz(-123)) == -123);
ok (mpq(mpq(-123)) == -123);
ok (mpq(mpf(-123)) == -123);
{ tie my $t, 'Mytie', -123; ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', '-123'; ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', substr('1-1231',1,4); ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', -123.0; ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', mpz(-123); ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', mpq(-123); ok (mpq($t) == -123); }
{ tie my $t, 'Mytie', mpf(-123); ok (mpq($t) == -123); }
ok (mpq($ivnv_2p128) == $str_2p128);
{ tie my $t, 'Mytie', $ivnv_2p128; ok (mpq($t) == $str_2p128); }
ok (mpq('3/2') == mpq(3,2));
ok (mpq('3/1') == mpq(3,1));
ok (mpq('-3/2') == mpq(-3,2));
ok (mpq('-3/1') == mpq(-3,1));
ok (mpq('0x3') == mpq(3,1));
ok (mpq('0b111') == mpq(7,1));
ok (mpq('0b0') == mpq(0,1));
ok (mpq($uv_max) > 0);
ok (mpq($uv_max) == mpq($uv_max_str));
{ tie my $t, 'Mytie', $uv_max; ok (mpq($t) > 0); }
{ tie my $t, 'Mytie', $uv_max; ok (mpq($t) == mpq($uv_max_str)); }
{ my $x = 123.5;
kill (0, $x);
ok (mpq($x) == 123.5);
tie my $t, 'Mytie', $x;
ok (mpq($t) == 123.5);
}
ok (abs(mpq(0)) == 0);
ok (abs(mpq(123)) == 123);
ok (abs(mpq(-123)) == 123);
{ my $x = mpq(-123); $x = abs($x); ok ($x == 123); }
{ my $x = mpq(0); $x = abs($x); ok ($x == 0); }
{ my $x = mpq(123); $x = abs($x); ok ($x == 123); }
{ tie my $t, 'Mytie', mpq(0); ok (abs($t) == 0); }
{ tie my $t, 'Mytie', mpq(123); ok (abs($t) == 123); }
{ tie my $t, 'Mytie', mpq(-123); ok (abs($t) == 123); }
ok (mpq(0) != 1);
ok (mpq(0) != -1);
ok (mpq(1) != 0);
ok (mpq(1) != -1);
ok (mpq(-1) != 0);
ok (mpq(-1) != 1);
ok (mpq(3,2) > 1);
ok (mpq(3,2) < 2);
ok (mpq(0) < 1.0);
ok (mpq(0) < '1');
ok (mpq(0) < substr('-1',1,1));
ok (mpq(0) < mpz(1));
ok (mpq(0) < mpq(1));
ok (mpq(0) < mpf(1));
ok (mpq(0) < $uv_max);
ok (mpf(0) == 0);
ok (mpf('0') == 0);
ok (mpf(substr('101',1,1)) == 0);
ok (mpf(0.0) == 0);
ok (mpf(mpz(0)) == 0);
ok (mpf(mpq(0)) == 0);
ok (mpf(mpf(0)) == 0);
{ tie my $t, 'Mytie', 0; ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', '0'; ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', substr('101',1,1); ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', 0.0; ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', mpz(0); ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', mpq(0); ok (mpf($t) == 0); }
{ tie my $t, 'Mytie', mpf(0); ok (mpf($t) == 0); }
ok (mpf(-123) == -123);
ok (mpf('-123') == -123);
ok (mpf(substr('1-1231',1,4)) == -123);
ok (mpf(-123.0) == -123);
ok (mpf(mpz(-123)) == -123);
ok (mpf(mpq(-123)) == -123);
ok (mpf(mpf(-123)) == -123);
{ tie my $t, 'Mytie', -123; ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', '-123'; ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', substr('1-1231',1,4); ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', -123.0; ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', mpz(-123); ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', mpq(-123); ok (mpf($t) == -123); }
{ tie my $t, 'Mytie', mpf(-123); ok (mpf($t) == -123); }
ok (mpf($ivnv_2p128) == $str_2p128);
{ tie my $t, 'Mytie', $ivnv_2p128; ok (mpf($t) == $str_2p128); }
ok (mpf(-1.5) == -1.5);
ok (mpf(-1.0) == -1.0);
ok (mpf(-0.5) == -0.5);
ok (mpf(0) == 0);
ok (mpf(0.5) == 0.5);
ok (mpf(1.0) == 1.0);
ok (mpf(1.5) == 1.5);
ok (mpf("-1.5") == -1.5);
ok (mpf("-1.0") == -1.0);
ok (mpf("-0.5") == -0.5);
ok (mpf("0") == 0);
ok (mpf("0.5") == 0.5);
ok (mpf("1.0") == 1.0);
ok (mpf("1.5") == 1.5);
ok (mpf($uv_max) > 0);
ok (mpf($uv_max) == mpf($uv_max_str));
{ tie my $t, 'Mytie', $uv_max; ok (mpf($t) > 0); }
{ tie my $t, 'Mytie', $uv_max; ok (mpf($t) == mpf($uv_max_str)); }
{ my $x = 123.5;
kill (0, $x);
ok (mpf($x) == 123.5);
tie my $t, 'Mytie', $x;
ok (mpf($t) == 123.5);
}
ok (abs(mpf(0)) == 0);
ok (abs(mpf(123)) == 123);
ok (abs(mpf(-123)) == 123);
{ my $x = mpf(-123); $x = abs($x); ok ($x == 123); }
{ my $x = mpf(0); $x = abs($x); ok ($x == 0); }
{ my $x = mpf(123); $x = abs($x); ok ($x == 123); }
{ tie my $t, 'Mytie', mpf(0); ok (abs($t) == 0); }
{ tie my $t, 'Mytie', mpf(123); ok (abs($t) == 123); }
{ tie my $t, 'Mytie', mpf(-123); ok (abs($t) == 123); }
ok (mpf(0) != 1);
ok (mpf(0) != -1);
ok (mpf(1) != 0);
ok (mpf(1) != -1);
ok (mpf(-1) != 0);
ok (mpf(-1) != 1);
ok (mpf(0) < 1.0);
ok (mpf(0) < '1');
ok (mpf(0) < substr('-1',1,1));
ok (mpf(0) < mpz(1));
ok (mpf(0) < mpq(1));
ok (mpf(0) < mpf(1));
ok (mpf(0) < $uv_max);
{ my $x = mpf(0); ok ("$x" eq "0"); }
{ my $x = mpf(123); ok ("$x" eq "123"); }
{ my $x = mpf(-123); ok ("$x" eq "-123"); }
{ my $f = mpf(0.25); ok ("$f" eq "0.25"); }
{ my $f = mpf(-0.25); ok ("$f" eq "-0.25"); }
{ my $f = mpf(1.25); ok ("$f" eq "1.25"); }
{ my $f = mpf(-1.25); ok ("$f" eq "-1.25"); }
{ my $f = mpf(1000000); ok ("$f" eq "1000000"); }
{ my $f = mpf(-1000000); ok ("$f" eq "-1000000"); }
{ my $r = randstate(); ok (defined $r); }
{ my $r = randstate('lc_2exp', 1, 2, 3); ok (defined $r); }
{ my $r = randstate('lc_2exp_size', 64); ok (defined $r); }
{ my $r = randstate('lc_2exp_size', 999999999); ok (! defined $r); }
{ my $r = randstate('mt'); ok (defined $r); }
{ # copying a randstate results in same sequence
my $r1 = randstate('lc_2exp_size', 64);
$r1->seed(123);
my $r2 = randstate($r1); for (1 .. 20) {
my $z1 = mpz_urandomb($r1, 20);
my $z2 = mpz_urandomb($r2, 20);
ok ($z1 == $z2);
}
}
# in perl 5.005 uv_max is only 32-bits on a 64-bit system, so won't exceed a # long # ok (! GMP::fits_slong_p($uv_max));
ok (GMP::fits_slong_p(0.0));
ok (GMP::fits_slong_p('0'));
ok (GMP::fits_slong_p(substr('999999999999999999999999999999',1,1)));
ok (! mpz("-9999999999999999999999999999999999999999999")->fits_slong_p());
ok ( mpz(-123)->fits_slong_p());
ok ( mpz(0)->fits_slong_p());
ok ( mpz(123)->fits_slong_p());
ok (! mpz("9999999999999999999999999999999999999999999")->fits_slong_p());
ok (! mpq("-9999999999999999999999999999999999999999999")->fits_slong_p());
ok ( mpq(-123)->fits_slong_p());
ok ( mpq(0)->fits_slong_p());
ok ( mpq(123)->fits_slong_p());
ok (! mpq("9999999999999999999999999999999999999999999")->fits_slong_p());
ok (! mpf("-9999999999999999999999999999999999999999999")->fits_slong_p());
ok ( mpf(-123)->fits_slong_p());
ok ( mpf(0)->fits_slong_p());
ok ( mpf(123)->fits_slong_p());
ok (! mpf("9999999999999999999999999999999999999999999")->fits_slong_p());
ok (get_str(-123) eq '-123');
ok (get_str('-123') eq '-123');
ok (get_str(substr('x-123x',1,4)) eq '-123');
ok (get_str(mpz(-123)) eq '-123');
ok (get_str(mpq(-123)) eq '-123');
ok (get_str(-123,10) eq '-123');
ok (get_str('-123',10) eq '-123');
ok (get_str(substr('x-123x',1,4),10) eq '-123');
ok (get_str(mpz(-123),10) eq '-123');
ok (get_str(mpq(-123),10) eq '-123');
ok (get_str(-123,16) eq '-7b');
ok (get_str('-123',16) eq '-7b');
ok (get_str(substr('x-123x',1,4),16) eq '-7b');
ok (get_str(mpz(-123),16) eq '-7b');
ok (get_str(mpq(-123),16) eq '-7b');
ok (get_str(-123,-16) eq '-7B');
ok (get_str('-123',-16) eq '-7B');
ok (get_str(substr('x-123x',1,4),-16) eq '-7B');
ok (get_str(mpz(-123),-16) eq '-7B');
ok (get_str(mpq(-123),-16) eq '-7B');
# is a float in past versions of perl without UV type
{ my ($str, $exp) = get_str($uv_max);
ok ($str eq $uv_max_str); }
ok (get_str(mpq(5/8)) eq "5/8");
ok (get_str(mpq(-5/8)) eq "-5/8");
ok (get_str(mpq(255/256),16) eq "ff/100");
ok (get_str(mpq(255/256),-16) eq "FF/100");
ok (get_str(mpq(-255/256),16) eq "-ff/100");
ok (get_str(mpq(-255/256),-16) eq "-FF/100");
{ my ($s,$e) = get_str(1.5, 10); ok ($s eq '15'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(1.5), 10); ok ($s eq '15'); ok ($e == 1); }
{ my ($s,$e) = get_str(-1.5, 10); ok ($s eq '-15'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(-1.5), 10); ok ($s eq '-15'); ok ($e == 1); }
{ my ($s,$e) = get_str(1.5, 16); ok ($s eq '18'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(1.5), 16); ok ($s eq '18'); ok ($e == 1); }
{ my ($s,$e) = get_str(-1.5, 16); ok ($s eq '-18'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(-1.5), 16); ok ($s eq '-18'); ok ($e == 1); }
{ my ($s,$e) = get_str(65536.0, 16); ok ($s eq '1'); ok ($e == 5); }
{ my ($s,$e) = get_str(mpf(65536.0), 16); ok ($s eq '1'); ok ($e == 5); }
{ my ($s,$e) = get_str(1.625, 16); ok ($s eq '1a'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(1.625), 16); ok ($s eq '1a'); ok ($e == 1); }
{ my ($s,$e) = get_str(1.625, -16); ok ($s eq '1A'); ok ($e == 1); }
{ my ($s,$e) = get_str(mpf(1.625), -16); ok ($s eq '1A'); ok ($e == 1); }
{ my ($s, $e) = get_str(255.0,16,0); ok ($s eq "ff"); ok ($e == 2); }
{ my ($s, $e) = get_str(mpf(255.0),16,0); ok ($s eq "ff"); ok ($e == 2); }
{ my ($s, $e) = get_str(255.0,-16,0); ok ($s eq "FF"); ok ($e == 2); }
{ my ($s, $e) = get_str(mpf(255.0),-16,0); ok ($s eq "FF"); ok ($e == 2); }
ok ( GMP::integer_p (0));
ok ( GMP::integer_p (123));
ok ( GMP::integer_p (-123));
ok ( GMP::integer_p ($uv_max));
ok ( GMP::integer_p (0.0));
ok ( GMP::integer_p (123.0));
ok ( GMP::integer_p (-123.0));
ok (! GMP::integer_p (0.5));
ok (! GMP::integer_p (123.5));
ok (! GMP::integer_p (-123.5));
ok ( GMP::integer_p ('0'));
ok ( GMP::integer_p ('123'));
ok ( GMP::integer_p ('-123'));
ok (! GMP::integer_p ('0.5'));
ok (! GMP::integer_p ('123.5'));
ok (! GMP::integer_p ('-123.5'));
ok (! GMP::integer_p ('5/8'));
ok ( GMP::integer_p (mpz(1)));
ok ( GMP::integer_p (mpq(1)));
ok (! GMP::integer_p (mpq(1,2)));
ok ( GMP::integer_p (mpf(1.0)));
ok (! GMP::integer_p (mpf(1.5)));
ok ( odd_p(mpz(-3)));
ok (! odd_p(mpz(-2)));
ok ( odd_p(mpz(-1)));
ok (! odd_p(mpz(0)));
ok ( odd_p(mpz(1)));
ok (! odd_p(mpz(2)));
ok ( odd_p(mpz(3)));
sub via_printf {
my $s;
open TEMP, ">test.tmp" or die;
GMP::printf TEMP @_;
close TEMP or die;
open TEMP, "<test.tmp" or die;
read (TEMP, $s, 1024);
close TEMP or die;
unlink 'test.tmp';
return $s;
}
ok (sprintf ("%d", mpz(123)) eq '123');
ok (sprintf ("%d %d %d", 456, mpz(123), 789) eq '456 123 789');
ok (sprintf ("%d", mpq(15,16)) eq '15/16');
ok (sprintf ("%f", mpf(1.5)) eq '1.500000');
ok (sprintf ("%.2f", mpf(1.5)) eq '1.50');
ok (sprintf ("%*d", 6, 123) eq ' 123');
ok (sprintf ("%*d", 6, mpz(123)) eq ' 123');
ok (sprintf ("%*d", 6, mpq(15,16)) eq ' 15/16');
ok (sprintf ("%x", 123) eq '7b');
ok (sprintf ("%x", mpz(123)) eq '7b');
ok (sprintf ("%X", 123) eq '7B');
ok (sprintf ("%X", mpz(123)) eq '7B');
ok (sprintf ("%#x", 123) eq '0x7b');
ok (sprintf ("%#x", mpz(123)) eq '0x7b');
ok (sprintf ("%#X", 123) eq '0X7B');
ok (sprintf ("%#X", mpz(123)) eq '0X7B');
ok (sprintf ("%x", mpq(15,16)) eq 'f/10');
ok (sprintf ("%X", mpq(15,16)) eq 'F/10');
ok (sprintf ("%#x", mpq(15,16)) eq '0xf/0x10');
ok (sprintf ("%#X", mpq(15,16)) eq '0XF/0X10');
ok (sprintf ("%*.*f", 10, 3, 1.25) eq ' 1.250');
ok (sprintf ("%*.*f", 10, 3, mpf(1.5)) eq ' 1.500');
ok (via_printf ("%d", mpz(123)) eq '123');
ok (via_printf ("%d %d %d", 456, mpz(123), 789) eq '456 123 789');
ok (via_printf ("%d", mpq(15,16)) eq '15/16');
ok (via_printf ("%f", mpf(1.5)) eq '1.500000');
ok (via_printf ("%.2f", mpf(1.5)) eq '1.50');
ok (via_printf ("%*d", 6, 123) eq ' 123');
ok (via_printf ("%*d", 6, mpz(123)) eq ' 123');
ok (via_printf ("%*d", 6, mpq(15,16)) eq ' 15/16');
ok (via_printf ("%x", 123) eq '7b');
ok (via_printf ("%x", mpz(123)) eq '7b');
ok (via_printf ("%X", 123) eq '7B');
ok (via_printf ("%X", mpz(123)) eq '7B');
ok (via_printf ("%#x", 123) eq '0x7b');
ok (via_printf ("%#x", mpz(123)) eq '0x7b');
ok (via_printf ("%#X", 123) eq '0X7B');
ok (via_printf ("%#X", mpz(123)) eq '0X7B');
ok (via_printf ("%x", mpq(15,16)) eq 'f/10');
ok (via_printf ("%X", mpq(15,16)) eq 'F/10');
ok (via_printf ("%#x", mpq(15,16)) eq '0xf/0x10');
ok (via_printf ("%#X", mpq(15,16)) eq '0XF/0X10');
ok (via_printf ("%*.*f", 10, 3, 1.25) eq ' 1.250');
ok (via_printf ("%*.*f", 10, 3, mpf(1.5)) eq ' 1.500');
if ($] > 5.00503) { if (! do'test2.pl') {
die "Cannot run test2.pl\n";
}
}
#------------------------------------------------------------------------------ # $# stuff # # For some reason "local $#" doesn't leave $# back at its default undefined # state when exiting the block.
{ local $# = 'hi %.0f there';
my $f = mpf(123);
ok ("$f" eq 'hi 123 there'); }
# Local variables: # perl-indent-level: 2 # End:
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.53Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.