This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Math::BigInt from 1.999701 to 1.999704
[perl5.git] / cpan / Math-BigInt / t / mbimbf.t
CommitLineData
58cde26e
JH
1#!/usr/bin/perl -w
2
c4a6f826 3# test rounding, accuracy, precision and fallback, round_mode and mixing
ee15d750 4# of classes
58cde26e
JH
5
6use strict;
3167abe5 7use Test::More tests => 684
0dceeee6 8 + 26; # own tests
ee15d750 9
06ce15ad
SH
10use Math::BigInt lib => 'Calc';
11use Math::BigFloat;
ee15d750 12
61f5c3f5 13use vars qw/$mbi $mbf/;
ee15d750 14
61f5c3f5
T
15$mbi = 'Math::BigInt';
16$mbf = 'Math::BigFloat';
58cde26e 17
4aa37faf 18require 't/mbimbf.inc';
58cde26e 19
61f5c3f5 20# some tests that won't work with subclasses, since the things are only
9681bfa6 21# guaranteed in the Math::BigInt/BigFloat (unless subclass chooses to support
61f5c3f5 22# this)
58cde26e 23
61f5c3f5
T
24Math::BigInt->round_mode('even'); # reset for tests
25Math::BigFloat->round_mode('even'); # reset for tests
58cde26e 26
3167abe5
NC
27is ($Math::BigInt::rnd_mode,'even');
28is ($Math::BigFloat::rnd_mode,'even');
027dc388 29
61f5c3f5 30my $x = eval '$mbi->round_mode("huhmbi");';
3167abe5 31like ($@, qr/^Unknown round mode 'huhmbi' at/);
dccbb853 32
61f5c3f5 33$x = eval '$mbf->round_mode("huhmbf");';
3167abe5 34like ($@, qr/^Unknown round mode 'huhmbf' at/);
ee15d750 35
027dc388
JH
36# old way (now with test for validity)
37$x = eval '$Math::BigInt::rnd_mode = "huhmbi";';
3167abe5 38like ($@, qr/^Unknown round mode 'huhmbi' at/);
61f5c3f5 39$x = eval '$Math::BigFloat::rnd_mode = "huhmbf";';
3167abe5 40like ($@, qr/^Unknown round mode 'huhmbf' at/);
027dc388 41# see if accessor also changes old variable
3167abe5
NC
42$mbi->round_mode('odd'); is ($Math::BigInt::rnd_mode,'odd');
43$mbf->round_mode('odd'); is ($Math::BigInt::rnd_mode,'odd');
58cde26e 44
b3abae2a
JH
45foreach my $class (qw/Math::BigInt Math::BigFloat/)
46 {
3167abe5
NC
47 is ($class->accuracy(5),5); # set A
48 is ($class->precision(), undef); # and now P must be cleared
49 is ($class->precision(5),5); # set P
50 is ($class->accuracy(), undef); # and now A must be cleared
b3abae2a
JH
51 }
52
990fb837
RGS
53foreach my $class (qw/Math::BigInt Math::BigFloat/)
54 {
55 $class->accuracy(42);
56 my $x = $class->new(123); # $x gets A of 42, too!
3167abe5
NC
57 is ($x->accuracy(),42); # really?
58 is ($x->accuracy(undef),42); # $x has no A, but the
990fb837
RGS
59 # global is still in effect for $x
60 # so the return value of that operation should
61 # be 42, not undef
3167abe5 62 is ($x->accuracy(),42); # so $x should still have A = 42
93c87d9d
T
63 $class->accuracy(undef); # reset for further tests
64 $class->precision(undef);
990fb837 65 }
93c87d9d
T
66# bug with flog(Math::BigFloat,Math::BigInt)
67$x = Math::BigFloat->new(100);
68$x = $x->blog(Math::BigInt->new(10));
69
3167abe5 70is ($x,2);
0dceeee6
RGS
71
72# bug until v1.88 for sqrt() with enough digits
73for my $i (80,88,100)
74 {
75 $x = Math::BigFloat->new("1." . ("0" x $i) . "1");
76 $x = $x->bsqrt;
3167abe5 77 is ($x, 1);
0dceeee6 78 }