File: bigroot.t

package info (click to toggle)
perl 5.8.4-8sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,128 kB
  • ctags: 31,422
  • sloc: perl: 224,262; ansic: 155,398; sh: 32,253; pascal: 7,747; lisp: 6,121; makefile: 2,341; cpp: 2,035; yacc: 1,019; java: 23
file content (71 lines) | stat: -rwxr-xr-x 1,916 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w

# Test broot function (and bsqrt() function, since it is used by broot()).

# It is too slow to be simple included in bigfltpm.inc, where it would get
# executed 3 times.

# But it is better to test the numerical functionality, instead of not testing
# it at all.

use Test;
use strict;

BEGIN
  {
  $| = 1;
  # to locate the testing files
  my $location = $0; $location =~ s/bigroot.t//i;
  if ($ENV{PERL_CORE})
    {
    # testing with the core distribution
    @INC = qw(../lib);
    }
  unshift @INC, '../lib';
  if (-d 't')
    {
    chdir 't';
    require File::Spec;
    unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
    }
  else
    {
    unshift @INC, $location;
    }
  print "# INC = @INC\n";

  plan tests => 4 * 2;
  }

use Math::BigFloat;
use Math::BigInt;

my $cl = "Math::BigFloat";
my $c = "Math::BigInt";

# 2 ** 240 = 
# 1766847064778384329583297500742918515827483896875618958121606201292619776

# takes way too long
#test_broot ('2','240', 8, undef,   '1073741824');
#test_broot ('2','240', 9, undef,   '106528681.3099908308759836475139583940127');
#test_broot ('2','120', 9, undef,   '10321.27324073880096577298929482324664787');
#test_broot ('2','120', 17, undef,   '133.3268493632747279600707813049418888729');

test_broot ('2','120', 8, undef,   '32768');
test_broot ('2','60', 8, undef,   '181.0193359837561662466161566988413540569');
test_broot ('2','60', 9, undef,   '101.5936673259647663841091609134277286651');
test_broot ('2','60', 17, undef,   '11.54672461623965153271017217302844672562');

sub test_broot
  {
  my ($x,$n,$y,$scale,$result) = @_;

  my $s = $scale || 'undef';
  print "# Try: $cl $x->bpow($n)->broot($y,$s) == $result:\n"; 
   ok ($cl->new($x)->bpow($n)->broot($y,$scale),$result);
  $result =~ s/\..*//;
  print "# Try: $c $x->bpow($n)->broot($y,$s) == $result:\n"; 
   ok ($c->new($x)->bpow($n)->broot($y,$scale),$result);
  }