3 # test the helper math routines in Math::BigFloat
11 # to locate the testing files
12 my $location = $0; $location =~ s/_e_math.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";
34 use Math::BigFloat lib => 'Calc';
36 #############################################################################
39 my $a = Math::BigInt::Calc->_new("123");
40 my $b = Math::BigInt::Calc->_new("321");
42 my ($x, $xs) = Math::BigFloat::_e_add($a,$b,'+','+');
43 is (_str($x,$xs), '+444', 'add two positive numbers');
44 is (_str($a,''), '444', 'a modified');
46 ($x,$xs) = _add (123,321,'+','+');
47 is (_str($x,$xs), '+444', 'add two positive numbers');
49 ($x,$xs) = _add (123,321,'+','-');
50 is (_str($x,$xs), '-198', 'add +x + -y');
51 ($x,$xs) = _add (123,321,'-','+');
52 is (_str($x,$xs), '+198', 'add -x + +y');
54 ($x,$xs) = _add (321,123,'-','+');
55 is (_str($x,$xs), '-198', 'add -x + +y');
56 ($x,$xs) = _add (321,123,'+','-');
57 is (_str($x,$xs), '+198', 'add +x + -y');
59 ($x,$xs) = _add (10,1,'+','-');
60 is (_str($x,$xs), '+9', 'add 10 + -1');
61 ($x,$xs) = _add (10,1,'-','+');
62 is (_str($x,$xs), '-9', 'add -10 + +1');
63 ($x,$xs) = _add (1,10,'-','+');
64 is (_str($x,$xs), '+9', 'add -1 + 10');
65 ($x,$xs) = _add (1,10,'+','-');
66 is (_str($x,$xs), '-9', 'add 1 + -10');
68 #############################################################################
71 $a = Math::BigInt::Calc->_new("123");
72 $b = Math::BigInt::Calc->_new("321");
73 ($x, $xs) = Math::BigFloat::_e_sub($b,$a,'+','+');
74 is (_str($x,$xs), '+198', 'sub two positive numbers');
75 is (_str($b,''), '198', 'a modified');
77 ($x,$xs) = _sub (123,321,'+','-');
78 is (_str($x,$xs), '+444', 'sub +x + -y');
79 ($x,$xs) = _sub (123,321,'-','+');
80 is (_str($x,$xs), '-444', 'sub -x + +y');
84 my ($a,$b,$as,$bs) = @_;
86 my $aa = Math::BigInt::Calc->_new($a);
87 my $bb = Math::BigInt::Calc->_new($b);
88 my ($x, $xs) = Math::BigFloat::_e_add($aa,$bb,$as,$bs);
89 is (Math::BigInt::Calc->_str($x), Math::BigInt::Calc->_str($aa),
96 my ($a,$b,$as,$bs) = @_;
98 my $aa = Math::BigInt::Calc->_new($a);
99 my $bb = Math::BigInt::Calc->_new($b);
100 my ($x, $xs) = Math::BigFloat::_e_sub($aa,$bb,$as,$bs);
101 is (Math::BigInt::Calc->_str($x), Math::BigInt::Calc->_str($aa),
110 $s . Math::BigInt::Calc->_str($x);