Commit | Line | Data |
a0ac753d |
1 | #!/usr/bin/perl -w |
2 | |
3 | # Math::BigFloat->new had a bug where it would assume any object is a |
4 | # BigInt which broke overloaded non-BigInts. |
5 | |
6 | use Test::More tests => 4; |
7 | |
8 | |
9 | package Overloaded::Num; |
10 | |
11 | use overload '0+' => sub { ${$_[0]} }, |
12 | fallback => 1; |
13 | sub new { |
14 | my($class, $num) = @_; |
15 | return bless \$num, $class; |
16 | } |
17 | |
18 | |
19 | package main; |
20 | |
21 | use Math::BigFloat; |
22 | |
23 | my $overloaded_num = Overloaded::Num->new(2.23); |
24 | is $overloaded_num, 2.23; |
25 | |
26 | my $bigfloat = Math::BigFloat->new($overloaded_num); |
27 | is $bigfloat, 2.23, 'BigFloat->new accepts overloaded numbers'; |
28 | |
29 | my $bigint = Math::BigInt->new(Overloaded::Num->new(3)); |
30 | is $bigint, 3, 'BigInt->new accepts overloaded numbers'; |
31 | |
32 | is( Math::BigFloat->new($bigint), 3, 'BigFloat from BigInt' ); |