HN2new | past | comments | ask | show | jobs | submitlogin

In the general case (for values of n bigger than double precision floats support), the Binet formula is slower.

The author’s proposed solution only works up to n = 78. If you want to speed up the calculation for small values, just cache them all.



ofc, but it is possible for compiler to be smart enough to"discover" this? and use similar heuristics for other similar problems?


In this particular case, it would not be useful.

Personally I don’t ever want a compiler trying to replace straight-forward integer algorithms with floating point formulas. YMMV.


No (and no time soon unless it's a special case coded in manually), but some simpler things are possible, see e.g. https://hackernews.hn/item?id=16259157.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: