fun fact: even with "format long", matlab doesn't always print enough
digits to reconstruct the number

On Tue, Nov 4, 2014 at 8:35 PM, Stuart Brorson <[email protected]> wrote:

> Just to follow up on this topic, here's what Matlab does:
>
>  2*10.97 + 23.9985
>>>
>>
> ans =
>
>    45.9385
>
>  2*10.97 + 23.9985 == 45.9385
>>>
>>
> ans =
>
>      0
>
>  format long
>>> 2*10.97 + 23.9985
>>>
>>
> ans =
>
>   45.938500000000005
>
>  2*10.97 + 23.9985 == 45.938500000000005
>>>
>>
> ans =
>
>      1
>
> Note that Matlab's display value is 45.9385, but the actual result is
> 45.938500000000005.  You only see the display value if you set the
> display to show all digits ("format long")
>
> Stuart
>
>
>
> On Wed, 5 Nov 2014, K Leo wrote:
>
>  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 <[email protected]
>>> <mailto:[email protected]>> 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
>>>         <[email protected]> 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