Commit | Line | Data |
---|---|---|
06ce15ad | 1 | #!perl |
3a427a11 RGS |
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 | ||
6b10d254 SH |
11 | use strict; # restrict unsafe constructs |
12 | use warnings; # enable optional warnings | |
06ce15ad | 13 | |
4aa37faf | 14 | use Test::More tests => 4 * 2; |
3a427a11 | 15 | |
54b49d96 | 16 | use Math::BigFloat only => 'Calc'; |
3a427a11 RGS |
17 | use Math::BigInt; |
18 | ||
6b10d254 SH |
19 | my $mbf = "Math::BigFloat"; |
20 | my $mbi = "Math::BigInt"; | |
3a427a11 | 21 | |
6b10d254 | 22 | # 2 ** 240 = |
3a427a11 RGS |
23 | # 1766847064778384329583297500742918515827483896875618958121606201292619776 |
24 | ||
25 | # takes way too long | |
6b10d254 SH |
26 | #test_broot('2', '240', 8, undef, |
27 | # '1073741824'); | |
28 | #test_broot('2', '240', 9, undef, | |
29 | # '106528681.3099908308759836475139583940127'); | |
30 | #test_broot('2', '120', 9, undef, | |
31 | # '10321.27324073880096577298929482324664787'); | |
32 | #test_broot('2', '120', 17, undef, | |
33 | # '133.3268493632747279600707813049418888729'); | |
34 | ||
35 | test_broot('2', '120', 8, undef, | |
36 | '32768'); | |
37 | test_broot('2', '60', 8, undef, | |
38 | '181.0193359837561662466161566988413540569'); | |
39 | test_broot('2', '60', 9, undef, | |
40 | '101.5936673259647663841091609134277286651'); | |
41 | test_broot('2', '60', 17, undef, | |
42 | '11.54672461623965153271017217302844672562'); | |
43 | ||
44 | sub test_broot { | |
45 | my ($x, $n, $y, $scale, $expected) = @_; | |
46 | ||
47 | my $s = $scale || 'undef'; | |
48 | is($mbf->new($x)->bpow($n)->broot($y, $scale), $expected, | |
49 | "Try: $mbf->new($x)->bpow($n)->broot($y, $s) == $expected"); | |
50 | $expected =~ s/\..*//; | |
51 | is($mbi->new($x)->bpow($n)->broot($y, $scale), $expected, | |
52 | "Try: $mbi->new($x)->bpow($n)->broot($y, $s) == $expected"); | |
53 | } |