1#!perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 2818            # tests in require'd file
7                         + 19;          # tests in this file
8
9use Math::BigInt only => 'Calc';
10use Math::BigFloat;
11
12our ($CLASS, $LIB);
13$CLASS = "Math::BigFloat";
14$LIB   = Math::BigInt -> config('lib');         # backend library
15
16is($CLASS->config("class"), $CLASS, qq|$CLASS->config("class")|);
17is($CLASS->config("with"),  $LIB,   qq|$CLASS->config("with")|);
18
19# bug #17447: Can't call method Math::BigFloat->bsub, not a valid method
20my $c = Math::BigFloat->new('123.3');
21is($c->bsub(123), '0.3',
22   qq|\$c = Math::BigFloat -> new("123.3"); \$y = \$c -> bsub("123")|);
23
24# Bug until Math::BigInt v1.86, the scale wasn't treated as a scalar:
25$c = Math::BigFloat->new('0.008');
26my $d = Math::BigFloat->new(3);
27my $e = $c->bdiv(Math::BigFloat->new(3), $d);
28
29is($e, '0.00267', '0.008 / 3 = 0.0027');
30
31my $x;
32
33#############################################################################
34# bgcd() as function, class method and instance method.
35
36my $gcd0 = Math::BigFloat::bgcd(-12, 18, 27);
37isa_ok($gcd0, "Math::BigFloat", "bgcd() as function");
38is($gcd0, 3, "bgcd() as function");
39
40my $gcd1 = Math::BigFloat->bgcd(-12, 18, 27);
41isa_ok($gcd1, "Math::BigFloat", "bgcd() as class method");
42is($gcd1, 3, "bgcd() as class method");
43
44$x = Math::BigFloat -> new(-12);
45my $gcd2 = $x -> bgcd(18, 27);
46isa_ok($gcd2, "Math::BigFloat", "bgcd() as instance method");
47is($gcd2, 3, "bgcd() as instance method");
48is($x, -12, "bgcd() does not modify invocand");
49
50#############################################################################
51# blcm() as function, class method and instance method.
52
53my $lcm0 = Math::BigFloat::blcm(-12, 18, 27);
54isa_ok($lcm0, "Math::BigFloat", "blcm() as function");
55is($lcm0, 108, "blcm() as function");
56
57my $lcm1 = Math::BigFloat->blcm(-12, 18, 27);
58isa_ok($lcm1, "Math::BigFloat", "blcm() as class method");
59is($lcm1, 108, "blcm() as class method");
60
61$x = Math::BigFloat -> new(-12);
62my $lcm2 = $x -> blcm(18, 27);
63isa_ok($lcm2, "Math::BigFloat", "blcm() as instance method");
64is($lcm2, 108, "blcm() as instance method");
65is($x, -12, "blcm() does not modify invocand");
66
67#############################################################################
68
69SKIP: {
70    skip("skipping test which is not for this backend", 1)
71      unless $LIB eq 'Math::BigInt::Calc';
72    is(ref($e->{_e}->[0]), '', '$e->{_e}->[0] is a scalar');
73}
74
75require './t/bigfltpm.inc';     # all tests here for sharing
76