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 approximations const sqrt5 float64 = 2.236067977499789696409173668731276235441 // math.Sqrt(5.0) const phi float64 = 1.618033988749894848204586834365638117720 // (1 + sqrt5) / 2 const psi float64 = -0.6180339887498948482045868343656381177203 // (1 - sqrt5) / 2 Here is the evaluation: (https://play.golang.org/p/InwNEeyv4Bx) func fibonacci(n uint) uint64 { float_n := float64(n) a := math.Pow(phi, float_n) b := math.Pow(psi, float_n) rounded := math.Floor(a/sqrt5 + 0.5) both := (a - b) / sqrt5 fmt.Printf("%4d: rounded = %19.0f, both = %40.20f, delta = %+27.20e\n", n, rounded, both, both-rounded) return uint64(rounded) } And the result: 1: rounded = 1, both = 1.00000000000000000000, delta = +0.00000000000000000000e+00 2: rounded = 1, both = 1.00000000000000000000, delta = +0.00000000000000000000e+00 3: rounded = 2, both = 2.00000000000000000000, delta = +0.00000000000000000000e+00 4: rounded = 3, both = 3.00000000000000000000, delta = +0.00000000000000000000e+00 5: rounded = 5, both = 5.00000000000000000000, delta = +0.00000000000000000000e+00 6: rounded = 8, both = 8.00000000000000000000, delta = +0.00000000000000000000e+00 7: rounded = 13, both = 13.00000000000000000000, delta = +0.00000000000000000000e+00 8: rounded = 21, both = 21.00000000000000000000, delta = +0.00000000000000000000e+00 9: rounded = 34, both = 34.00000000000000000000, delta = +0.00000000000000000000e+00 10: rounded = 55, both = 54.99999999999999289457, delta = -7.10542735760100185871e-15 11: rounded = 89, both = 89.00000000000000000000, delta = +0.00000000000000000000e+00 12: rounded = 144, both = 143.99999999999997157829, delta = -2.84217094304040074348e-14 13: rounded = 233, both = 232.99999999999994315658, delta = -5.68434188608080148697e-14 14: rounded = 377, both = 377.00000000000005684342, delta = +5.68434188608080148697e-14 15: rounded = 610, both = 610.00000000000000000000, delta = +0.00000000000000000000e+00 16: rounded = 987, both = 986.99999999999977262632, delta = -2.27373675443232059479e-13 17: rounded = 1597, both = 1596.99999999999977262632, delta = -2.27373675443232059479e-13 18: rounded = 2584, both = 2584.00000000000000000000, delta = +0.00000000000000000000e+00 19: rounded = 4181, both = 4181.00000000000000000000, delta = +0.00000000000000000000e+00 20: rounded = 6765, both = 6764.99999999999909050530, delta = -9.09494701772928237915e-13 21: rounded = 10946, both = 10945.99999999999818101060, delta = -1.81898940354585647583e-12 22: rounded = 17711, both = 17710.99999999999636202119, delta = -3.63797880709171295166e-12 23: rounded = 28657, both = 28656.99999999999636202119, delta = -3.63797880709171295166e-12 24: rounded = 46368, both = 46367.99999999999272404239, delta = -7.27595761418342590332e-12 25: rounded = 75025, both = 75025.00000000000000000000, delta = +0.00000000000000000000e+00 26: rounded = 121393, both = 121392.99999999998544808477, delta = -1.45519152283668518066e-11 27: rounded = 196418, both = 196418.00000000000000000000, delta = +0.00000000000000000000e+00 28: rounded = 317811, both = 317811.00000000000000000000, delta = +0.00000000000000000000e+00 29: rounded = 514229, both = 514228.99999999994179233909, delta = -5.82076609134674072266e-11 30: rounded = 832040, both = 832039.99999999988358467817, delta = -1.16415321826934814453e-10 31: rounded = 1346269, both = 1346268.99999999976716935635, delta = -2.32830643653869628906e-10 32: rounded = 2178309, both = 2178309.00000000000000000000, delta = +0.00000000000000000000e+00 33: rounded = 3524578, both = 3524577.99999999953433871269, delta = -4.65661287307739257812e-10 34: rounded = 5702887, both = 5702886.99999999906867742538, delta = -9.31322574615478515625e-10 35: rounded = 9227465, both = 9227465.00000000000000000000, delta = +0.00000000000000000000e+00 36: rounded = 14930352, both = 14930351.99999999813735485077, delta = -1.86264514923095703125e-09 37: rounded = 24157817, both = 24157816.99999999627470970154, delta = -3.72529029846191406250e-09 38: rounded = 39088169, both = 39088168.99999999254941940308, delta = -7.45058059692382812500e-09 39: rounded = 63245986, both = 63245985.99999999254941940308, delta = -7.45058059692382812500e-09 40: rounded = 102334155, both = 102334154.99999998509883880615, delta = -1.49011611938476562500e-08 41: rounded = 165580141, both = 165580140.99999997019767761230, delta = -2.98023223876953125000e-08 42: rounded = 267914296, both = 267914295.99999994039535522461, delta = -5.96046447753906250000e-08 43: rounded = 433494437, both = 433494437.00000000000000000000, delta = +0.00000000000000000000e+00 44: rounded = 701408733, both = 701408732.99999988079071044922, delta = -1.19209289550781250000e-07 45: rounded = 1134903170, both = 1134903169.99999976158142089844, delta = -2.38418579101562500000e-07 46: rounded = 1836311903, both = 1836311903.00000000000000000000, delta = +0.00000000000000000000e+00 47: rounded = 2971215073, both = 2971215072.99999952316284179688, delta = -4.76837158203125000000e-07 48: rounded = 4807526976, both = 4807526975.99999904632568359375, delta = -9.53674316406250000000e-07 49: rounded = 7778742049, both = 7778742048.99999809265136718750, delta = -1.90734863281250000000e-06 50: rounded = 12586269025, both = 12586269024.99999809265136718750, delta = -1.90734863281250000000e-06 51: rounded = 20365011074, both = 20365011074.00000000000000000000, delta = +0.00000000000000000000e+00 52: rounded = 32951280099, both = 32951280098.99999237060546875000, delta = -7.62939453125000000000e-06 53: rounded = 53316291173, both = 53316291172.99998474121093750000, delta = -1.52587890625000000000e-05 54: rounded = 86267571272, both = 86267571271.99998474121093750000, delta = -1.52587890625000000000e-05 55: rounded = 139583862445, both = 139583862444.99996948242187500000, delta = -3.05175781250000000000e-05 56: rounded = 225851433717, both = 225851433716.99996948242187500000, delta = -3.05175781250000000000e-05 57: rounded = 365435296162, both = 365435296161.99993896484375000000, delta = -6.10351562500000000000e-05 58: rounded = 591286729879, both = 591286729878.99987792968750000000, delta = -1.22070312500000000000e-04 59: rounded = 956722026041, both = 956722026040.99987792968750000000, delta = -1.22070312500000000000e-04 60: rounded = 1548008755920, both = 1548008755919.99975585937500000000, delta = -2.44140625000000000000e-04 61: rounded = 2504730781961, both = 2504730781960.99951171875000000000, delta = -4.88281250000000000000e-04 62: rounded = 4052739537881, both = 4052739537880.99902343750000000000, delta = -9.76562500000000000000e-04 63: rounded = 6557470319842, both = 6557470319841.99902343750000000000, delta = -9.76562500000000000000e-04 64: rounded = 10610209857723, both = 10610209857722.99804687500000000000, delta = -1.95312500000000000000e-03 65: rounded = 17167680177565, both = 17167680177564.99609375000000000000, delta = -3.90625000000000000000e-03 66: rounded = 27777890035288, both = 27777890035287.99609375000000000000, delta = -3.90625000000000000000e-03 67: rounded = 44945570212853, both = 44945570212852.99218750000000000000, delta = -7.81250000000000000000e-03 68: rounded = 72723460248141, both = 72723460248140.98437500000000000000, delta = -1.56250000000000000000e-02 69: rounded = 117669030460994, both = 117669030460993.98437500000000000000, delta = -1.56250000000000000000e-02 70: rounded = 190392490709135, both = 190392490709134.96875000000000000000, delta = -3.12500000000000000000e-02 71: rounded = 308061521170129, both = 308061521170129.00000000000000000000, delta = +0.00000000000000000000e+00 72: rounded = 498454011879264, both = 498454011879263.87500000000000000000, delta = -1.25000000000000000000e-01 73: rounded = 806515533049393, both = 806515533049392.87500000000000000000, delta = -1.25000000000000000000e-01 74: rounded = 1304969544928657, both = 1304969544928656.75000000000000000000, delta = -2.50000000000000000000e-01 75: rounded = 2111485077978050, both = 2111485077978049.50000000000000000000, delta = -5.00000000000000000000e-01 76: rounded = 3416454622906706, both = 3416454622906706.00000000000000000000, delta = +0.00000000000000000000e+00 77: rounded = 5527939700884756, both = 5527939700884755.00000000000000000000, delta = -1.00000000000000000000e+00 78: rounded = 8944394323791464, both = 8944394323791463.00000000000000000000, delta = -1.00000000000000000000e+00 79: rounded = 14472334024676218, both = 14472334024676218.00000000000000000000, delta = +0.00000000000000000000e+00 80: rounded = 23416728348467676, both = 23416728348467676.00000000000000000000, delta = +0.00000000000000000000e+00 81: rounded = 37889062373143896, both = 37889062373143896.00000000000000000000, delta = +0.00000000000000000000e+00 82: rounded = 61305790721611584, both = 61305790721611584.00000000000000000000, delta = +0.00000000000000000000e+00 83: rounded = 99194853094755488, both = 99194853094755488.00000000000000000000, delta = +0.00000000000000000000e+00 84: rounded = 160500643816367040, both = 160500643816367040.00000000000000000000, delta = +0.00000000000000000000e+00 85: rounded = 259695496911122528, both = 259695496911122528.00000000000000000000, delta = +0.00000000000000000000e+00 86: rounded = 420196140727489600, both = 420196140727489600.00000000000000000000, delta = +0.00000000000000000000e+00 87: rounded = 679891637638612096, both = 679891637638612096.00000000000000000000, delta = +0.00000000000000000000e+00 88: rounded = 1100087778366101632, both = 1100087778366101632.00000000000000000000, delta = +0.00000000000000000000e+00 89: rounded = 1779979416004713728, both = 1779979416004713728.00000000000000000000, delta = +0.00000000000000000000e+00 90: rounded = 2880067194370815488, both = 2880067194370815488.00000000000000000000, delta = +0.00000000000000000000e+00 91: rounded = 4660046610375529472, both = 4660046610375529472.00000000000000000000, delta = +0.00000000000000000000e+00 92: rounded = 7540113804746344448, both = 7540113804746344448.00000000000000000000, delta = +0.00000000000000000000e+00 Yuval, please do the same test on your computer. Please evaluate the two powers as separate expressions shown here ("a" and "b"). Let's see if things agree. On Mon, Apr 30, 2018 at 10:18 AM andrey mirtchovski <mirtchov...@gmail.com> wrote: > every time float accuracy is mentioned i think of this: > > http://0.30000000000000004.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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Michael T. Jones michael.jo...@gmail.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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.