in reply to Re^2: Using big numbers correctly
in thread Using big numbers correctly

Well I seem to have solved the print problem with print 'crt solution =', $crt1 -> bdstr(),"\n"; So I have solved my own problem I think. 2 hours of my time I'll never get back though!

Replies are listed 'Best First'.
Re^4: Using big numbers correctly
by syphilis (Archbishop) on Oct 16, 2018 at 11:48 UTC
    Well I seem to have solved the print problem with print 'crt solution =', $crt1 -> bdstr(),"\n";

    You can just as well use print $crt1, "\n"; or say $crt1;.
    But printf "%.0f\n", $crt1; will simply round the value 954846259588805228035541587771 to a double:
    use warnings; use strict; use Math::BigFloat; use feature ':5.10'; my $x = Math::BigFloat->new('954846259588805228035541587771'); print $x->bdstr(), "\n"; print $x, "\n"; say $x; printf "%.0f\n", $x; printf "%.29e\n", 954846259588805228035541587771; __END__ Outputs: 954846259588805228035541587771 954846259588805228035541587771 954846259588805228035541587771 954846259588805282215996948480 9.54846259588805282215996948480e+29
    You get the correct output using "print" and "say" owing to operator overloading, and because $crt1 is a Math::BigFloat object.
    Similarly, it doesn't matter whether you multiply/divide/add/subtract $crt1 with an integer, a perl floating point value, another Math::BigFloat object, or even a string.
    This, again, can be attributed to operator overloading:
    use warnings; use strict; use Math::BigFloat; use feature ':5.10'; my $x = Math::BigFloat->new('954846259588805228035541587771'); print $x * 2, "\n"; print $x * 2.5, "\n"; print $x * Math::BigFloat->new('2.5'), "\n"; print $x * "2.5"; __END__ Outputs: 1909692519177610456071083175542 2387115648972013070088853969427.5 2387115648972013070088853969427.5 2387115648972013070088853969427.5

    Cheers,
    Rob