{"id":186756,"date":"2023-03-15T10:35:05","date_gmt":"2023-03-15T14:35:05","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=186756"},"modified":"2023-03-15T17:18:14","modified_gmt":"2023-03-15T21:18:14","slug":"really-large-numbers-in-r","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/","title":{"rendered":"Really Large Numbers in R"},"content":{"rendered":"\n<p>This post will discuss ways of handling huge numbers in&nbsp;<a href=\"https:\/\/theautomatic.net\/category\/r\/\">R<\/a>&nbsp;using the&nbsp;<strong>gmp<\/strong>&nbsp;package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-gmp-package\"><strong>The gmp package<\/strong><\/h2>\n\n\n\n<p>The&nbsp;<strong>gmp<\/strong>&nbsp;package provides us a way of dealing with really large numbers in R. For example, let\u2019s suppose we want to multiple 10<sup>250<\/sup>&nbsp;by itself. Mathematically we know the result should be 10<sup>500<\/sup>. But if we try this calculation in base R we get Inf for infinity.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = 10^250\n \nnum^2 # Inf<\/pre>\n\n\n\n<p>However, we can get around this using the&nbsp;<strong>gmp<\/strong>&nbsp;package. Here, we can convert the integer 10 to an object of the&nbsp;<em>bigz<\/em>&nbsp;class. This is an implementation that allows us to handle very large numbers. Once we convert an integer to a&nbsp;<em>bigz<\/em>&nbsp;object, we can use it to perform calculations with regular numbers in R (there\u2019s a small caveat coming).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">library(gmp)\n \nnum = as.bigz(10)\n \n(num^250) * (num^250)\n \n# or directly 10^500\nnum^500<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"640\" height=\"271\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/gpm-as-bigz-TheAutomatic.net_.jpg\" alt=\"\" class=\"wp-image-186759 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/gpm-as-bigz-TheAutomatic.net_.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/gpm-as-bigz-TheAutomatic.net_-300x127.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/271;\" \/><\/figure>\n\n\n\n<p>One note that we need to be careful about is what numbers we use to convert to&nbsp;<em>bigz<\/em>&nbsp;objects. In the example above, we convert the integer 10 to&nbsp;<em>bigz<\/em>. This works fine for our calculations because 10 is not a very large number in itself. However, let\u2019s suppose we had converted 10<sup>250<\/sup>&nbsp;to a&nbsp;<em>bigz<\/em>&nbsp;object instead. If we do this, the number 10<sup>250<\/sup>&nbsp;becomes a double data type, which causes a loss in precision for such a number. Thus the result we see below isn\u2019t really 10<sup>250<\/sup>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = 10^250\n \nas.bigz(num)\n \nnum<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"640\" height=\"191\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/double-losing-precision-in-r-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186760 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/double-losing-precision-in-r-the-automatic-net.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/double-losing-precision-in-r-the-automatic-net-300x90.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/191;\" \/><\/figure>\n\n\n\n<p>A way around this is to input the number we want as a character into&nbsp;<em>as.bigz<\/em>. For example, we know that 10<sup>250<\/sup>&nbsp;is the number 1 followed by 250 zeros. We can create a character that represents this number like below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = paste0(\"1\", paste(rep(\"0\", 250), collapse = \"\"))<\/pre>\n\n\n\n<p>Thus, we can use this idea to create&nbsp;<em>bigz<\/em>&nbsp;objects:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">as.bigz(num)<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"640\" height=\"83\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/as-bigz-on-a-character-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186762 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/as-bigz-on-a-character-the-automatic-net.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/as-bigz-on-a-character-the-automatic-net-300x39.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/83;\" \/><\/figure>\n\n\n\n<p>In case you run into issues with the above line returning an NA value, you might want to try turning scientific notation off. You can do that using the base&nbsp;<em>options<\/em>&nbsp;command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">options(scipen = 999)<\/pre>\n\n\n\n<p>If scientific notation is not turned off, you may have cases where the character version of the number looks like below, which results in an NA being returned by&nbsp;<em>as.bigz<\/em>.<\/p>\n\n\n\n<p><strong>\u201c1e250\u201d<\/strong><\/p>\n\n\n\n<p>In general, numbers can be input to&nbsp;<strong>gmp<\/strong>&nbsp;functions as characters to avoid this or other precision issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Finding the next prime<\/strong><\/h2>\n\n\n\n<p>The&nbsp;<strong>gmp<\/strong>&nbsp;package can find the first prime larger than an input number using the&nbsp;<em>nextprime<\/em>&nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = \"100000000000000000000000000000000000000000000000000\"\n \nnextprime(num)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"569\" height=\"72\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/next-prime-number-1-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186770 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/next-prime-number-1-the-automatic-net.jpg 569w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/next-prime-number-1-the-automatic-net-300x38.jpg 300w\" data-sizes=\"(max-width: 569px) 100vw, 569px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 569px; aspect-ratio: 569\/72;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Find the GCD of two huge numbers<\/strong><\/h2>\n\n\n\n<p>We can find the GCD of two large numbers using the&nbsp;<em>gcd<\/em>&nbsp;function:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = \"2452345345234123123178\"\nnum2 = \"23459023850983290589042\"\n \ngcd(num, num2) # returns 2<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Factoring numbers into primes<\/strong><\/h2>\n\n\n\n<p><strong>gmp<\/strong>&nbsp;also provides a way to factor numbers into primes. We can do this using the&nbsp;<em>factorize<\/em>&nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num = \"2452345345234123123178\"\n \nfactorize(num)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"544\" height=\"75\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/factorize-large-number-in-r-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186773 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/factorize-large-number-in-r-the-automatic-net.jpg 544w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/factorize-large-number-in-r-the-automatic-net-300x41.jpg 300w\" data-sizes=\"(max-width: 544px) 100vw, 544px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 544px; aspect-ratio: 544\/75;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Matrices of large numbers<\/strong><\/h2>\n\n\n\n<p><strong>gmp<\/strong>&nbsp;also supports creating matrices with&nbsp;<em>bigz<\/em>&nbsp;objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">num1 &lt;- \"1000000000000000000000000000\"\nnum2 &lt;- \"10000000000000000000000000000000\"\nnum3 &lt;- \"100000000000000000000000000000000000000\"\nnum4 &lt;- \"100000000000000000000000000000000000000000000000\"\n \nnums &lt;- c(as.bigz(num1), as.bigz(num2), as.bigz(num3), as.bigz(num4))\n \nmatrix(nums, nrow = 2)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"640\" height=\"79\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/matrix-large-numbers-in-r-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186778 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/matrix-large-numbers-in-r-the-automatic-net.jpg 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/matrix-large-numbers-in-r-the-automatic-net-300x37.jpg 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/79;\" \/><\/figure>\n\n\n\n<p>We can also perform typical operations with our matrix, like find its inverse, using base R functions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">solve(m)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"576\" height=\"176\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/inverse-of-matrix-in-r-the-automatic-net.jpg\" alt=\"\" class=\"wp-image-186780 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/inverse-of-matrix-in-r-the-automatic-net.jpg 576w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/inverse-of-matrix-in-r-the-automatic-net-300x92.jpg 300w\" data-sizes=\"(max-width: 576px) 100vw, 576px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 576px; aspect-ratio: 576\/176;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Sampling random (large) numbers uniformly<\/strong><\/h2>\n\n\n\n<p>We can sample large numbers from a discrete uniform distribution using the&nbsp;<em>urand.bigz<\/em>&nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">urand.bigz(nb = 100, size = 5000, seed = 0)<\/pre>\n\n\n\n<p>The&nbsp;<em>nb<\/em>&nbsp;parameter represents how many integers we want to sample. Thus, in this example, we\u2019ll get 100 integers returned.&nbsp;<em>size = 5000<\/em>&nbsp;tells the function to sample the integers from the inclusive range of 0 to 2<sup>5000<\/sup>&nbsp;\u2013 1. In general you can sample from the range 0 to 2<sup>size<\/sup>&nbsp;\u2013 1.<\/p>\n\n\n\n<p>To learn more about&nbsp;<strong>gmp<\/strong>,&nbsp;<a href=\"https:\/\/cran.r-project.org\/web\/packages\/gmp\/gmp.pdf\">click here for its vignette<\/a>.<\/p>\n\n\n\n<p><em>Originally posted on the <a href=\"https:\/\/theautomatic.net\/2019\/08\/16\/really-large-numbers-in-r\/\">TheAutomatic.net<\/a> Blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.<\/p>\n","protected":false},"author":388,"featured_media":25708,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,352,344,342],"tags":[806,14930,487,7811],"contributors-categories":[13695],"class_list":{"0":"post-186756","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-quant-north-america","12":"category-quant-regions","13":"category-r-development","14":"tag-data-science","15":"tag-gmp-package","16":"tag-r","17":"tag-r-rstats","18":"contributors-categories-theautomatic-net"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Really Large Numbers in R | IBKR Quant<\/title>\n<meta name=\"description\" content=\"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/186756\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Really Large Numbers in R | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-15T14:35:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-15T21:18:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"535\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"Really Large Numbers in R\",\n\t            \"datePublished\": \"2023-03-15T14:35:05+00:00\",\n\t            \"dateModified\": \"2023-03-15T21:18:14+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/\"\n\t            },\n\t            \"wordCount\": 573,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/binary-code.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"gmp package\",\n\t                \"R\",\n\t                \"R rstats\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant North America\",\n\t                \"Quant Regions\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/\",\n\t            \"name\": \"Really Large Numbers in R | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/binary-code.jpg\",\n\t            \"datePublished\": \"2023-03-15T14:35:05+00:00\",\n\t            \"dateModified\": \"2023-03-15T21:18:14+00:00\",\n\t            \"description\": \"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/really-large-numbers-in-r\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/binary-code.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/11\\\/binary-code.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 535,\n\t            \"caption\": \"Algo Trading\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Really Large Numbers in R | IBKR Quant","description":"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/186756\/","og_locale":"en_US","og_type":"article","og_title":"Really Large Numbers in R | IBKR Campus US","og_description":"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/","og_site_name":"IBKR Campus US","article_published_time":"2023-03-15T14:35:05+00:00","article_modified_time":"2023-03-15T21:18:14+00:00","og_image":[{"width":900,"height":535,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"Really Large Numbers in R","datePublished":"2023-03-15T14:35:05+00:00","dateModified":"2023-03-15T21:18:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/"},"wordCount":573,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","keywords":["Data Science","gmp package","R","R rstats"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","Quant North America","Quant Regions","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/","name":"Really Large Numbers in R | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","datePublished":"2023-03-15T14:35:05+00:00","dateModified":"2023-03-15T21:18:14+00:00","description":"This post will discuss ways of handling huge numbers in\u00a0R\u00a0using the\u00a0gmp\u00a0package.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/really-large-numbers-in-r\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","width":900,"height":535,"caption":"Algo Trading"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/11\/binary-code.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/186756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=186756"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/186756\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/25708"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=186756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=186756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=186756"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=186756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}