1N/A#!/usr/bin/perl -w
1N/A
1N/A# Test broot function (and bsqrt() function, since it is used by broot()).
1N/A
1N/A# It is too slow to be simple included in bigfltpm.inc, where it would get
1N/A# executed 3 times.
1N/A
1N/A# But it is better to test the numerical functionality, instead of not testing
1N/A# it at all.
1N/A
1N/Ause Test;
1N/Ause strict;
1N/A
1N/ABEGIN
1N/A {
1N/A $| = 1;
1N/A # to locate the testing files
1N/A my $location = $0; $location =~ s/bigroot.t//i;
1N/A if ($ENV{PERL_CORE})
1N/A {
1N/A # testing with the core distribution
1N/A @INC = qw(../lib);
1N/A }
1N/A unshift @INC, '../lib';
1N/A if (-d 't')
1N/A {
1N/A chdir 't';
1N/A require File::Spec;
1N/A unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
1N/A }
1N/A else
1N/A {
1N/A unshift @INC, $location;
1N/A }
1N/A print "# INC = @INC\n";
1N/A
1N/A plan tests => 4 * 2;
1N/A }
1N/A
1N/Ause Math::BigFloat;
1N/Ause Math::BigInt;
1N/A
1N/Amy $cl = "Math::BigFloat";
1N/Amy $c = "Math::BigInt";
1N/A
1N/A# 2 ** 240 =
1N/A# 1766847064778384329583297500742918515827483896875618958121606201292619776
1N/A
1N/A# takes way too long
1N/A#test_broot ('2','240', 8, undef, '1073741824');
1N/A#test_broot ('2','240', 9, undef, '106528681.3099908308759836475139583940127');
1N/A#test_broot ('2','120', 9, undef, '10321.27324073880096577298929482324664787');
1N/A#test_broot ('2','120', 17, undef, '133.3268493632747279600707813049418888729');
1N/A
1N/Atest_broot ('2','120', 8, undef, '32768');
1N/Atest_broot ('2','60', 8, undef, '181.0193359837561662466161566988413540569');
1N/Atest_broot ('2','60', 9, undef, '101.5936673259647663841091609134277286651');
1N/Atest_broot ('2','60', 17, undef, '11.54672461623965153271017217302844672562');
1N/A
1N/Asub test_broot
1N/A {
1N/A my ($x,$n,$y,$scale,$result) = @_;
1N/A
1N/A my $s = $scale || 'undef';
1N/A print "# Try: $cl $x->bpow($n)->broot($y,$s) == $result:\n";
1N/A ok ($cl->new($x)->bpow($n)->broot($y,$scale),$result);
1N/A $result =~ s/\..*//;
1N/A print "# Try: $c $x->bpow($n)->broot($y,$s) == $result:\n";
1N/A ok ($c->new($x)->bpow($n)->broot($y,$scale),$result);
1N/A }
1N/A