* andrey mirtchovski <mirtchov...@gmail.com> [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, the current algorithm used by math.Pow produces results that are far enough from the true value that it is worth opening an issue. > it would perhaps make sense to quantify the error margins that this > algorithm introduces. As far as the OP's question about why he needs to round in Go but truncate in C++, I am not convinced that the error in math.Pow is significant. Binet's formula, given exact (non-computer limited) values and calculations, will give exact integral values for the Fibonacci numbers. If you start with the assumption that using Binet's formula with IEEE floating point arithmetic will give results that are close enough to the correct value that you will have no trouble determining which integer is the right one, then the assumption that the error is between -0.5 and +0.5 is much more reasonable than the assumption that the error is in the range [0, 1). It is certainly plausible that one could prove that the error will always be positive, given known characteristics of the computer program's implementation of pow, among other things, but without such analysis, assuming that truncating the result will always give the correct answer is naive. I posit that the OP's C++ implementation only works because of specific characteristics of C++ library pow function, the last-mantissa-bit rounding of the value used for phi, and other aspects of the implementation that have not be adequately analyzed to be certain that the error is always positive. In short, the OP's assumption that the algorithm in his C++ program is correct is wrong; it just happens to work for the values tested. Both the C++ and the Go program should round the floating point result to get the correct integer. ...Marvin -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.