This code prints a random Float64 that requires more than 15 digits to
reconstruct:

while true
    x = rand()
    if parsefloat(@sprintf("%.15f", x)) != x
        println(x)
        break
    end
end


There are lots of them. What's more surprising is that if you replace 15
with anything up to 20, it still returns really quickly – at 21 it hangs.
This implies that values requiring up to 20 digits to print "honestly" are
quite common.

On Wed, Nov 5, 2014 at 1:53 PM, David van Leeuwen <
[email protected]> wrote:

> I couldn't resist this after my cholfact() revelation...
>
> On Wednesday, November 5, 2014 11:23:03 AM UTC+1, Stefan Karpinski wrote:
>>
>> Well, I'm not sure what the intention was, but this fact is true: for
>> floating-point values x and y of the same type, x == y is true if and only
>> if string(x) == string(y).
>>
>>
> julia> a = inv(eye(2))
>
> 2x2 Array{Float64,2}:
>
>  1.0  -0.0
>
>  0.0   1.0
>
> julia> a[1,2] == a[2,1]
>
> true
>
> julia> string(a[1,2]) == string(a[2,1])
>
> false
> (pardon the formatting, I don't seem to have a good handle on this in
> google groups)
>
> Cheers,
>
> ---david
>

Reply via email to