julia> 2*10.97 + 23.9985
45.938500000000005

julia> 2*10.97 + 23.9985 == 45.938500000000005
true

Amazing. I never expected this. Is floating point comparison going to be guaranteed?

On 2014年11月05日 08:48, Stefan Karpinski wrote:
Some systems round their answers as John said but it's easy to check that it's a lie:

    R version 3.1.0 (2014-04-10) -- "Spring Dance"
    > 2*10.97 + 23.9985
    [1] 45.9385
    > 2*10.97 + 23.9985 == 45.9385
    [1] FALSE

    This is perl 5, version 16, subversion 2 (v5.16.2)
      DB<1> x 2*10.97 + 23.9985
    0  45.9385
      DB<2> x 2*10.97 + 23.9985 == 45.9385
    0  ''


I don't have a working copy of Matlab right now, but I think it does this too.

On Tue, Nov 4, 2014 at 8:31 PM, Neil Devadasan <ndeva...@gmail.com <mailto:ndeva...@gmail.com>> wrote:

    Thanks

    On Tuesday, November 4, 2014 2:13:37 PM UTC-5, John Myles White
    wrote:

        Hi Neil,

        Julie does math the same way that all computers do math.
        You're probably coming from another language where a lot of
        effort is invested into pretending that computers offer a
        closer approximation to abstract mathematics than they
        actually do. Those systems have been lying to you.

        Put another way: you just took the red pill by using Julia.

         -- John

        On Nov 4, 2014, at 11:06 AM, Neil Devadasan
        <ndev...@gmail.com> wrote:

        > julia> f(x::Float64, y::Float64) = 2x + y;
        >
        > julia> f(10.97,23.9985)
        > 45.938500000000005
        >
        > The above method execution of function f returns an answer
        that I cannot understand.  Can someone clarify?
        >
        > Thank you.



Reply via email to