Skip to content
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

Basic arithmetic issue #33

Closed
Suedede opened this issue Mar 17, 2013 · 3 comments
Closed

Basic arithmetic issue #33

Suedede opened this issue Mar 17, 2013 · 3 comments

Comments

@Suedede
Copy link

Suedede commented Mar 17, 2013

julia> 10.3 * 3
30.900000000000002

julia> 10.3 * 3 == 30.9
false

When I type 10.3 * 3 I get 30.900000000000002 instead of 30.9, I'm no expert but I don't get this when I type it into R and I suspect something is wrong.

@ViralBShah
Copy link
Collaborator

That is indeed the right answer. Here is matlab:

>> format long
>> 10.3*3     

ans =

  30.900000000000002

This should have been filed at https://github.com/JuliaLang/julia/issues.

@Suedede
Copy link
Author

Suedede commented Mar 17, 2013

Allright then, thanks for being so polite and giving me a quick short answer.

@StefanKarpinski
Copy link
Collaborator

This is a weird place to file such a bug since it has nothing to do with Gadfly. A little more elaboration – R looks like its answer is exactly 30.9 because it rounds trailing digits when it prints numbers, effectively lying about their exact value. Checking equality with 30.9, however, reveals that the value is not actually the same:

> 10.3*3
[1] 30.9
> 10.3*3 == 30.9
[1] FALSE
>

Julia, on the other hand, prints all the digits required to reconstruct a floating point number exactly, so you can see that this value is not exactly 30.9. All these systems are converting the input 30.9 to the closest representable IEEE 754 64-bit floating-point number (30.9 is not exactly representable in binary), and then doing standard IEEE arithmetic to get this result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants