Commit | Line | Data |
3a427a11 |
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 | |
50109ad0 |
11 | use Test::More; |
3a427a11 |
12 | use strict; |
13 | |
14 | BEGIN |
15 | { |
16 | $| = 1; |
17 | # to locate the testing files |
18 | my $location = $0; $location =~ s/bigroot.t//i; |
19 | if ($ENV{PERL_CORE}) |
20 | { |
21 | # testing with the core distribution |
22 | @INC = qw(../lib); |
23 | } |
24 | unshift @INC, '../lib'; |
25 | if (-d 't') |
26 | { |
27 | chdir 't'; |
28 | require File::Spec; |
29 | unshift @INC, File::Spec->catdir(File::Spec->updir, $location); |
30 | } |
31 | else |
32 | { |
33 | unshift @INC, $location; |
34 | } |
35 | print "# INC = @INC\n"; |
36 | |
37 | plan tests => 4 * 2; |
38 | } |
39 | |
40 | use Math::BigFloat; |
41 | use Math::BigInt; |
42 | |
43 | my $cl = "Math::BigFloat"; |
44 | my $c = "Math::BigInt"; |
45 | |
46 | # 2 ** 240 = |
47 | # 1766847064778384329583297500742918515827483896875618958121606201292619776 |
48 | |
49 | # takes way too long |
50 | #test_broot ('2','240', 8, undef, '1073741824'); |
51 | #test_broot ('2','240', 9, undef, '106528681.3099908308759836475139583940127'); |
52 | #test_broot ('2','120', 9, undef, '10321.27324073880096577298929482324664787'); |
53 | #test_broot ('2','120', 17, undef, '133.3268493632747279600707813049418888729'); |
54 | |
55 | test_broot ('2','120', 8, undef, '32768'); |
56 | test_broot ('2','60', 8, undef, '181.0193359837561662466161566988413540569'); |
57 | test_broot ('2','60', 9, undef, '101.5936673259647663841091609134277286651'); |
58 | test_broot ('2','60', 17, undef, '11.54672461623965153271017217302844672562'); |
59 | |
60 | sub test_broot |
61 | { |
62 | my ($x,$n,$y,$scale,$result) = @_; |
63 | |
64 | my $s = $scale || 'undef'; |
50109ad0 |
65 | is ($cl->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $cl $x->bpow($n)->broot($y,$s) == $result"); |
3a427a11 |
66 | $result =~ s/\..*//; |
50109ad0 |
67 | is ($c->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $c $x->bpow($n)->broot($y,$s) == $result"); |
3a427a11 |
68 | } |
69 | |