New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Math::BigFloat - bug giving NaN on multiplying 1 * 1e-05 #15098
Comments
From @epaCreated by @epaPlease see the following test program: use Math::BigFloat; For me this prints the following: using ordinary scalar, x=1 t=1e-05 using BigFloat, x=1 t=1e-05 I can see no reason why in the last section 1e-05 * 1 should give NaN. Perl Info
|
From @pjacklamThis behaviour is as documented and as intended. Whether this is the most If we go to the core of what creates the NaN: You see, your call to int() creates a Math::BigInt. Multiplying 0.00001, or You can get around this in several ways. One is to use the following at the use Math::BigFloat; A second way is to use "$i = $p->bint();" rather than "$i = int($p)". A third way is to use "$t = Math::BigFloat->new("0.00001");" rather than I hope this helps. Peter |
The RT System itself - Status changed from 'new' to 'open' |
From @epaBut why do 0.0001 and 0.00001 behave differently? That cannot be right. On 20 Dec 2015, at 14:15, Peter John Acklam <pjacklam@gmail.com<mailto:pjacklam@gmail.com>> wrote: This behaviour is as documented and as intended. Whether this is the most sensible behaviour is debatable, but it is at least as it works now. If we go to the core of what creates the NaN: You see, your call to int() creates a Math::BigInt. Multiplying 0.00001, or any other non-integer, with a Math::BigInt creates a NaN, because a non-integer can't be represented as a Math::BigInt. You can get around this in several ways. One is to use the following at the top of your program: use Math::BigFloat; A second way is to use "$i = $p->bint();" rather than "$i = int($p)". A third way is to use "$t = Math::BigFloat->new("0.00001");" rather than letting $t be a scalar. I hope this helps. Peter ______________________________________________________________________ This email is intended only for the person to whom it is addressed and may contain confidential information. Any retransmission, copying, disclosure or other use of, this information by persons other than the intended recipient is prohibited. If you received this email in error, please contact the sender and delete the material. This email is for information only and is not intended as an offer or solicitation for the purchase or sale of any financial instrument. Wadhwani Asset Management LLP is a Limited Liability Partnership registered in England (OC303168) with registered office at 40 Berkeley Square, 3rd Floor, London, W1J 5AL. It is authorised and regulated by the Financial Conduct Authority. |
From @pjacklameda@waniasset.com:
Sorry for not noticing the different results. When I ran your code, I got NaN in both cases. When I ran your code with an older version of the Math-BigInt distribution (which contains the Math::BigFloat module), I was able to reproduce your result. It turns out that this is a bug that was fixed in version 1.999701 of the Math-BigInt distribution. It was released in Septeber this year. In earlier versions, Math::BigInt converted all non-integer values to NaNs EXCEPT numbers in the range -1 < x < 1 that were written as decimal numbers, i.e., as "0.0001", not "1e-4": So the reason for the different behaviour in the two cases is that the two numbers stringify differently: The number 0.0001 becomes the string "0.0001", but 0.00001 becomes the string "1e-5". That difference is essential. The first case hits the bug, but the second doesn't. You can actually see you get m=0 in both cases if you change your code to foreach my $t ("0.0001", "0.00001") { and you get NaN in both cases if you change your code to foreach my $t ("1e-4", "1e-5") { In any case, this is a bug that has been fixed, so I suggest you upgrade to Math-BigInt version 1.999701 or newer. As a friendly reminder, please include the version number of relevant modules, if you submit another Perl bug report. It just makes life a little bit easier for the developers. :-) Cheers, |
From @epaThanks for the explanation. Can the newer version of Math::BigFloat be added -- |
From @pjacklamma. 21. des. 2015 01.46.23 skrev eda@waniasset.com:
I don't know about 5.22.2, but 5.23.5 contains the most recent |
From @epaOK, so this will be fixed in perl 5.24 and so can be PENDING_RELEASE. -- |
From @tonycozOn Mon Dec 21 06:15:08 2015, eda@waniasset.com wrote:
The Math::Big* modules are now CPAN upstream, so closing this ticket. Tony |
@tonycoz - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#126960 (status was 'rejected')
Searchable as RT126960$
The text was updated successfully, but these errors were encountered: