Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does

by syphilis (Archbishop)
on Jan 05, 2017 at 23:54 UTC ( [id://1179044]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
in thread Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does

Computers can't be accurate with all fractions

But this is no excuse for -4.848e1 and -48.48 being treated as different values.

Cheers,
Rob
  • Comment on Re^2: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does

Replies are listed 'Best First'.
Re^3: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
by Laurent_R (Canon) on Jan 06, 2017 at 07:27 UTC
    Yes, sure, this is not satisfactory, but the bottom line, in C, in Perl and in most other programming languages, is that you should not compare floats for equality (unless you really know very well what you're doing). To check is two such numbers shall be deemed equal, one should check that the absolute value of their difference is smaller than a certain very small value.

    Perl 6 has a rational type, in which numbers are stored internally as a numerator and a denominator, allowing for accurate comparison of decimal numbers.

Re^3: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
by LanX (Saint) on Jan 06, 2017 at 00:03 UTC
    Yeah just updated it before I saw your reply.

    I think the way -48.48 is transformed into a float follows a different calculation path which rounds the last bit into another direction.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-24 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found