-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Possible rounding error when substractring two Float64 arrays #8667
Comments
That is because the display of arrays is different from scalars. The number is the same, e.g. julia> [1.0] .- [10^-7.]
1-element Array{Float64,1}:
1.0
julia> ([1.0] .- [10^-7.])[1]
0.9999999 |
Showing Arrays at the prompt, we round elements to 6 digits to save space. |
Aah ! Thanks ! |
This is confusing sometimes, but I'm not sure what we could do differently. When you do, e.g. rand(5,5), you really don't want to see all of those digits. |
Maybe one could prefix the rounded numbers with ~, to indicate that it is not shown in full precision. |
Not a bad idea. It's annoying that it would take up space for every value though. Maybe indicating in the array description that the values are rounded would be good. E.g.: julia> randn(5,5)
5x5 Array{Float64,2} (values rounded):
-1.58891 0.0413407 -0.249306 -0.214036 0.822793
-0.38166 2.42342 -0.537856 0.795775 -0.62094
-0.398926 -0.929601 -0.0779216 -1.90433 0.471998
0.744185 -0.642462 -0.381877 -0.84185 -1.24628
-1.60374 1.63264 -0.889873 -0.00555298 -0.243353 |
You're right, for big arrays it would propably look ugly with the prefix. Indicating in the array description looks pretty good to me, because that's the first thing I checked when I noticed that the numbers were not what I expected. |
Something that may make it more obvious would be to round values to a given number of digits, not of significant digits. Currently, you could believe that the numbers are exact, since some have more digits than others. This would also make the output aligned and more readable. Indicating that the values are rounded wouldn't hurt, though. |
Perhaps something to indicate how the rounding is done? julia> randn(5,5) On Mon, Oct 13, 2014 at 10:37 AM, Stefan Karpinski <[email protected]
|
+100 for adding a snippet about rounding values. I think this is just the solution to #6608 that we need. |
Yes it's a fine idea, but in #6608 the output was actually wrong: it |
When substracting a small float from a big float one gets the expected result:
Doing the same with an array gives an unexpected result:
Somehow numbers below 10^-6 get rounded to zero.
Is there something I did wrong or might this be a bug ?
The text was updated successfully, but these errors were encountered: