Re: [julia-users] How Julia do math operations

2014-11-05 Thread Stefan Karpinski
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). On Wed, Nov 5, 2014 at 5:36 AM, Steven G. Johnson stevenj@gmail.com wrote: On Tuesday, November 4, 2014 8:44:55 PM

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Stefan Karpinski
On Wed, Nov 5, 2014 at 2:48 AM, Jameson Nash vtjn...@gmail.com wrote: fun fact: even with format long, matlab doesn't always print enough digits to reconstruct the number Do you have an example? If true, this is rather horrifying. Is there simply no way to print a true value from Matlab then?

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Ivar Nesje
The matlab docs clearly specifies format long as 15 digits http://www.mathworks.se/help/matlab/matlab_prog/display-format-for-numeric-values.html. Julia usually prints 16 (or 17) digits for a call to rand(). This is a typical distribution of the number of digits from a `rand(1_000_000)` call

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Arnaud Amiel
You may want to check the isapprox function.

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Tamas Papp
IMO simulation is not necessary here --- double float is known to have 52 bits for the significand, so which tranlates to a bit less than 16 decimal digits, + 1 for rounding error (magnitude of rounding error is non-uniform when reading back from decimal), which is how you get 17, so clearly 15 is

Re: [julia-users] How Julia do math operations

2014-11-05 Thread David van Leeuwen
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) ==

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Stefan Karpinski
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,

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Patrick O'Leary
On Wednesday, November 5, 2014 4:25:16 AM UTC-6, Stefan Karpinski wrote: On Wed, Nov 5, 2014 at 2:48 AM, Jameson Nash vtjn...@gmail.com wrote: fun fact: even with format long, matlab doesn't always print enough digits to reconstruct the number Do you have an example? If true, this is

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Tamas Papp
I think that you are just running floats which are subnormal in a fixed-point decimal representation: with %.17f, they have (on average) a single 0 after the decimal dot, with %.18f, they have two, etc. Printing them with %f but a fixed number of digits is not the right way, since you waste digits

Re: [julia-users] How Julia do math operations

2014-11-05 Thread Stefan Karpinski
No, these aren't subnormal values, although they are small. Using %.16e does print them all accurately though, so that's a bit misleading. By hang I meant that it doesn't return quickly, not that it won't ever return. On Wed, Nov 5, 2014 at 2:27 PM, Tamas Papp tkp...@gmail.com wrote: I think

[julia-users] How Julia do math operations

2014-11-04 Thread Neil Devadasan
julia f(x::Float64, y::Float64) = 2x + y; julia f(10.97,23.9985) 45.9385005 The above method execution of function f returns an answer that I cannot understand. Can someone clarify? Thank you.

Re: [julia-users] How Julia do math operations

2014-11-04 Thread John Myles White
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

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Neil Devadasan
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

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Stefan Karpinski
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) DB1 x 2*10.97 + 23.9985 0 45.9385 DB2

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Miguel Bazdresch
On Matlab R2013b: 2*10.97 + 23.9985 ans = 45.9385 2*10.97 + 23.9985 == 45.9385 ans = 0 -- mb On Tue, Nov 4, 2014 at 7:48 PM, Stefan Karpinski ste...@karpinski.org 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

Re: [julia-users] How Julia do math operations

2014-11-04 Thread K Leo
julia 2*10.97 + 23.9985 45.9385005 julia 2*10.97 + 23.9985 == 45.9385005 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

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Stefan Karpinski
On Wed, Nov 5, 2014 at 2:06 AM, K Leo cnbiz...@gmail.com wrote: julia 2*10.97 + 23.9985 45.9385005 julia 2*10.97 + 23.9985 == 45.9385005 true Amazing. I never expected this. Is floating point comparison going to be guaranteed? What's shocking about this? What do you

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Stuart Brorson
Don't know what you mean by guaranteeing a floating point comparison. In any event, you should never check equality when comparing floating point numbers (except perhaps in special cases). Instead, use a tolerance: tol = 1e-12; if (abs(a-b) tol) # Close enough else # not equal end The

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Stuart Brorson
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.9385005 2*10.97 + 23.9985 == 45.9385005 ans = 1 Note that Matlab's display

Re: [julia-users] How Julia do math operations

2014-11-04 Thread K Leo
I meant this: to check whether 2 floating point valuables equal I had always had to do something like abs(x-y)1.e-5 (never simply x==y) in other languages. I wonder whether checking x==y would be sufficient in Julia? On 2014年11月05日 09:30, Stefan Karpinski wrote: On Wed, Nov 5, 2014 at 2:06

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Stefan Karpinski
The == check works exactly the same way in Julia as it does in other languages. It's the printing of the numbers that's more precise. On Wed, Nov 5, 2014 at 2:41 AM, K Leo cnbiz...@gmail.com wrote: I meant this: to check whether 2 floating point valuables equal I had always had to do something

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Steven G. Johnson
On Tuesday, November 4, 2014 8:42:02 PM UTC-5, K leo wrote: I meant this: to check whether 2 floating point valuables equal I had always had to do something like abs(x-y)1.e-5 (never simply x==y) in other languages. I wonder whether checking x==y would be sufficient in Julia? It

Re: [julia-users] How Julia do math operations

2014-11-04 Thread Steven G. Johnson
On Tuesday, November 4, 2014 8:44:55 PM UTC-5, Stefan Karpinski wrote: The == check works exactly the same way in Julia as it does in other languages. It's the printing of the numbers that's more precise. Maybe K. Leo was asking whether Julia always prints out enough decimal digits from