I calculate the Fibonacci numbers in R using this code:
fib <- function(n) { a = 0 b = 1 for (i in 1:n) { tmp = b b = a a = a + tmp } return (a) } sprintf("%.0f",fib(79))
Starting with fib (79), I get inaccurate results. For example: fib (79) = "14472334024676220", when the correct result according to this web should be: fib (79) = 14472334024676221
Using the fibonacci function from the numbers package I get the same inaccurate results. I assume this is due to the accuracy of the number in R.
How can I get around this restriction and get the exact Fibonacci numbers in R?
, . 10, .:). , gmp (, , ), .
require(gmp) fib <- function(n) { a = 0 b = 1 for (i in 1:n) { tmp = b b = a a = add.bigz(a, tmp) # gmp function } return (a) } fib(79)
, fib (79): 14472334024676221. fib (5000), 1045 , .
, 16 . 17. AFAIK R .
, . , , , , .
Source: https://habr.com/ru/post/1532470/More articles:Using BroadcastReceiver with PhoneStateListener functionality - androidBest practices including Angular Grails user interface - includeHow to get Capistrano 3 to use RVM ruby? - ruby-on-railsF # Compare two lists, perform different actions - f #Intel XDK disables rotation - androidHow to add a button, such as the status bar of the Messenger Messenger - iosИспользование API Диска Google - как показать список папок в корневой папке - androidThis addition has caused prospects to start slowly - c #Using AddXmlDocComputed in an F # Type Provider - f #Error making changes. Please try again later or contact App Store Developer Support - iosAll Articles