This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Document string- and number-specific bitops in perlop
[perl5.git] / dist / Math-BigInt / t / bigroot.t
1 #!/usr/bin/perl -w
2
3 # Test broot function (and bsqrt() function, since it is used by broot()).
4
5 # It is too slow to be simple included in bigfltpm.inc, where it would get
6 # executed 3 times.
7
8 # But it is better to test the numerical functionality, instead of not testing
9 # it at all.
10
11 use strict;
12 use Test::More tests => 4 * 2;
13
14 use Math::BigFloat;
15 use Math::BigInt;
16
17 my $cl = "Math::BigFloat";
18 my $c = "Math::BigInt";
19
20 # 2 ** 240 = 
21 # 1766847064778384329583297500742918515827483896875618958121606201292619776
22
23 # takes way too long
24 #test_broot ('2','240', 8, undef,   '1073741824');
25 #test_broot ('2','240', 9, undef,   '106528681.3099908308759836475139583940127');
26 #test_broot ('2','120', 9, undef,   '10321.27324073880096577298929482324664787');
27 #test_broot ('2','120', 17, undef,   '133.3268493632747279600707813049418888729');
28
29 test_broot ('2','120', 8, undef,   '32768');
30 test_broot ('2','60', 8, undef,   '181.0193359837561662466161566988413540569');
31 test_broot ('2','60', 9, undef,   '101.5936673259647663841091609134277286651');
32 test_broot ('2','60', 17, undef,   '11.54672461623965153271017217302844672562');
33
34 sub test_broot
35   {
36   my ($x,$n,$y,$scale,$result) = @_;
37
38   my $s = $scale || 'undef';
39   is ($cl->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $cl $x->bpow($n)->broot($y,$s) == $result");
40   $result =~ s/\..*//;
41   is ($c->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $c $x->bpow($n)->broot($y,$s) == $result");
42   }
43