On 19/06/2011 21:43, Patrick Dupre wrote:
On Sun, 19 Jun 2011, Rob Dixon wrote:
On 19/06/2011 14:07, Patrick Dupre wrote:
Hello,
I need to convert the result of an aritmetic operation on 2
bignum into a "normal" float (ie double)
I did not find a way to do this.
no bignum ;
my $res = $A - $B ;
gives me always a bignum ($res) if $A and $B are bignum.
Hey Patrick
I suggest you convert the values to strings, which will force them to be
converted to normal floats before the arithmetic is done.
no bignum ;
my $res = $A->bstr - $B->bstr;
There is not option like (double) $res ?
Not as such, but Perl uses the string and binary representations of
numbers interchangeably. The bstr method is fine as a conversion to
standard floating point, although it is something that you should avoid
doing repetitively if the efficiency of your code is significant.
It is also probably better to use Math::BigFloat instead of bignum,
so that you can better control which variables are big floats and
which are normal.
I also wonder why you want to convert big floats into normal ones?
The only reason I can think of is to improve execution speed.
Not really, I have a big application calling c procedures and I do
not want to make changes with are not usuable and even tricky.
However, I need to make a couple of operations in BigFloat.
So you have C code working on the Perl floating point values? Fair enough.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/