Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-05-06 Thread Yuval Lifshitz
seems like math accuracy issues are known, or even, by design. see: https://github.com/golang/go/issues/9546 https://github.com/golang/go/issues/9545 On Sunday, 6 May 2018 00:05:13 UTC+3, Paul Hankin wrote: > > On Friday, 27 April 2018 23:57:42 UTC+2, Michael Jones wrote: >> >> Yuval, >> >>

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-05-05 Thread Paul Hankin
On Friday, 27 April 2018 23:57:42 UTC+2, Michael Jones wrote: > > Yuval, > > There are fundamental issues here. > > 1. That equation (de Moivre, Binet) is from the algebra of ideal numbers. > Numbers of infinite precision. Not the realm of computer arithmetic. It > works fine with double

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-05-01 Thread Marvin Renich
* andrey mirtchovski [180430 17:41]: > > math.Pow does not give as precise answers as the C++ std lib. > > math pow doesn't just multiply X by itself Y times, it uses a > different algorithm: > > https://golang.org/src/math/pow.go#L40 Sure, I understand that. However,

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Michael Jones
using an optimally-precise Pow: 1: rounded = 1, both = 1., delta = +0.e+00 2: rounded = 1, both = 1., delta = +0.e+00 3: rounded = 2, both =

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread andrey mirtchovski
> math.Pow does not give as precise answers as the C++ std lib. math pow doesn't just multiply X by itself Y times, it uses a different algorithm: https://golang.org/src/math/pow.go#L40 it would perhaps make sense to quantify the error margins that this algorithm introduces. not sure what c++

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Marvin Renich
* Michael Jones [180430 13:54]: > Andrey, that's great! > > On the Fibonacci series evaluation, let's make sure that we're all doing > the same calculation. For completeness and safety, let's skip all library > values and derived values. Here are more-than-sufficient

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Michael Jones
Andrey, that's great! On the Fibonacci series evaluation, let's make sure that we're all doing the same calculation. For completeness and safety, let's skip all library values and derived values. Here are more-than-sufficient versions of the three constants in Yuval's code: // 40-decimal digit

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread andrey mirtchovski
every time float accuracy is mentioned i think of this: http://0.30004.com/ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Marvin Renich
* Yuval Lifshitz [180430 02:02]: > It seems like go and C++ are doing something different regarding floating > point arithmetic, but I cannot say one is better than the other. It is just > the that C++ consistently overshoots (hence truncation work), and go > consistently

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Yuval Lifshitz
It seems like go and C++ are doing something different regarding floating point arithmetic, but I cannot say one is better than the other. It is just the that C++ consistently overshoots (hence truncation work), and go consistently undershoots (this is why rounding is needed). For example, in

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Michael Jones
Not sure what you mean with "by design." The design here is the IEEE Standard for Floating-Point Arithmetic (IEEE 754). It is authoritative for Intel, AMD, IBM, Sun, etc. Typical (universal?) C and C++ implementations map 'float' to 32-bit IEEE 754 binary floating point and 'double' to the

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Yuval Lifshitz
in C/C++ (at least on my system) "float" 4 has 4 bytes (32bits) and double has 8 bytes (64bits). according to this: https://golang.org/pkg/math/ its is the same thing with go. On Sunday, 29 April 2018 22:27:23 UTC+3, Louki Sumirniy wrote: > > I could be wrong but float64 is 'float' and 'double

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Louki Sumirniy
I could be wrong but float64 is 'float' and 'double float' is float128. I dunno, I have not tinkered with these imprecise math types. That's just, essentially, what they were back in the olden days, like 20 years ago. 64 bit was basic float, 128 was double. I have been out of the loop for way

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Yuval Lifshitz
Thanks Michael. Is this "by design"? Does it worth an issue here ? On Sunday, 29 April 2018 18:06:23 UTC+3, Michael Jones wrote: > > yes. truncation and round-up are important differences between your c/c++ > code and the go code. > > On Sun, Apr 29, 2018 at

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Michael Jones
yes. truncation and round-up are important differences between your c/c++ code and the go code. On Sun, Apr 29, 2018 at 12:08 AM Yuval Lifshitz wrote: > (1) I understand the issue of limited precision, this is why I did not try > anything above F(59) But my concern was not

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-29 Thread Yuval Lifshitz
(1) I understand the issue of limited precision, this is why I did not try anything above F(59) But my concern was not the difference between algebra and the go implementation it was the different results I got with the C/C++ implementation (gcc 7.3.1): #include const double sqrt_5 =

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-27 Thread Michael Jones
Yuval, There are fundamental issues here. 1. That equation (de Moivre, Binet) is from the algebra of ideal numbers. Numbers of infinite precision. Not the realm of computer arithmetic. It works fine with double precision (go: float64, c/c++: double) up to F(75) but must fail for F(76) due to the

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-26 Thread Ian Lance Taylor
On Thu, Apr 26, 2018 at 1:17 AM, Yuval Lifshitz wrote: > > I ran into the following issue when started playing with go. Had the > following small program to calculate Fibonacci numbers using the closed > form: > > package "fib" > > import "math" > > var sqrt_5 = math.Sqrt(5.0)

[go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-26 Thread Yuval Lifshitz
Dear community, I ran into the following issue when started playing with go. Had the following small program to calculate Fibonacci numbers using the closed form: package "fib" import "math" var sqrt_5 = math.Sqrt(5.0) var psi = -1.0/math.Phi // had to add this to solve accuracy issue func