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
rounding error after division #1900
Comments
From ortmann@sparc.isl.netCreated by ortmann@pyrl.eyeUnexpected "int"ification caused a program crash at work today. perl -le ' expect to get 707: 1) I assume this is caused by slight truncation error due to base 2. Perl Info
|
From [Unknown Contact. See original ticket]
DB<1> $x = 5.999999999999999 So? Perhaps a stronger form of "use integer" should be the default --tom |
From @tamiasOn Wed, Apr 26, 2000 at 10:22:38PM -0500, Daniel Ortmann wrote:
perldoc -q decimal =head2 Why am I getting long decimals (eg, 19.9499999999999) instead of the The infinite set that a mathematician thinks of as the real numbers can Internally, your computer represents floating-point numbers in binary. However, 19.95 can't be precisely represented as a binary When a floating-point number gets printed, the binary floating-point This affects B<all> computer languages that represent decimal To get rid of the superfluous digits, just use a format (eg, |
From [Unknown Contact. See original ticket]
I am well aware of rounding issues. Restating: print "$n" # displays an implicitly rounded number No problem. I'll probably try something like the following: use subs qw( int ); I just thought I'd bring up the difference in case y'all wanted to make Thanks |
From @tamiasOn Thu, Apr 27, 2000 at 06:58:14PM -0500, Daniel Ortmann wrote:
Then I am at a loss as to your bug report.
"$n" does an implicit sprintf. sprintf() rounds floating point arguments. =item int EXPR =item int Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
I don't think that will have the result you seem to intend. If you want to
int() truncates, as it should. Ronald |
From @iabynnot-a-bug |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#3170 (status was 'resolved')
Searchable as RT3170$
The text was updated successfully, but these errors were encountered: