3 # Test blog function (and bpow, since it uses blog), as well as bexp().
11 # to locate the testing files
12 my $location = $0; $location =~ s/biglog.t//i;
15 # testing with the core distribution
18 unshift @INC, '../lib';
23 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
27 unshift @INC, $location;
29 print "# INC = @INC\n";
36 my $cl = "Math::BigRat";
38 #############################################################################
42 #is ($cl->new(2)->blog(), '0', "blog(2)");
43 #is ($cl->new(288)->blog(), '5',"blog(288)");
44 #is ($cl->new(2000)->blog(), '7', "blog(2000)");
46 #############################################################################
49 is ($cl->new(1)->bexp()->as_int(), '2', "bexp(1)");
50 is ($cl->new(2)->bexp()->as_int(), '7',"bexp(2)");
51 is ($cl->new(3)->bexp()->as_int(), '20', "bexp(3)");
53 # rounding not implemented yet
54 #is ($cl->new(3)->bexp(10), '20', "bexp(3,10)");
57 ok ($cl->new(-2)->blog(), 'NaN');
58 ok ($cl->new(-1)->blog(), 'NaN');
59 ok ($cl->new(-10)->blog(), 'NaN');
60 ok ($cl->new(-2,2)->blog(), 'NaN');
62 #############################################################################
63 # test bexp() with cached results
65 is ($cl->new(1)->bexp(),
66 '90933395208605785401971970164779391644753259799242' . '/' .
67 '33452526613163807108170062053440751665152000000000',
69 is ($cl->new(2)->bexp(1,40), $cl->new(1)->bexp(1,45)->bpow(2,40), 'bexp(2)');
71 is ($cl->new("12.5")->bexp(1,61), $cl->new(1)->bexp(1,65)->bpow(12.5,61), 'bexp(12.5)');
73 #############################################################################
74 # test bexp() with big values (non-cached)
76 is ($cl->new(1)->bexp(1,100)->as_float(100),
77 '2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427',
80 is ($cl->new("12.5")->bexp(1,91), $cl->new(1)->bexp(1,95)->bpow(12.5,91),
81 'bexp(12.5) to 91 digits');
83 #############################################################################
84 # some integer results
85 is ($cl->new(2)->bpow(32)->blog(2), '32', "2 ** 32");
86 is ($cl->new(3)->bpow(32)->blog(3), '32', "3 ** 32");
87 is ($cl->new(2)->bpow(65)->blog(2), '65', "2 ** 65");
89 my $x = Math::BigInt->new( '777' ) ** 256;
90 my $base = Math::BigInt->new( '12345678901234' );
91 is ($x->copy()->blog($base), 56, 'blog(777**256, 12345678901234)');
93 $x = Math::BigInt->new( '777' ) ** 777;
94 $base = Math::BigInt->new( '777' );
95 is ($x->copy()->blog($base), 777, 'blog(777**777, 777)');