1

If I run the factorial(1:200), the largest value is 7.257416e+306, any value above that is "Inf".

  1. Does this means the largest value inside R programming is 7.257416e+306. We can not calculate the value above factorial(170)?
  2. But when I run the code ".Machine$double.xmax", the biggest value is 1.797693e+308.

So, I am a bit confused, which one is the biggest value in R?

t3m2
  • 366
  • 1
  • 15
Zhe Wu
  • 75
  • 1
  • 1
  • 4

1 Answers1

4

The largest number in base R has nothing to do with the factorial function. The likelihood that the largest number is going to coincide with a factorial is very small. The largest representable number differs depending on your computer. You can see it by running. .Machine$double.xmax. Everything above that is Inf.

You see 171*factorial(170) is simply larger than your machine's .Machine$double.xmax even though factorial(170) is smaller.

If you want larger numbers in R consider the discussion in this question

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Grada Gukovic
  • 1,228
  • 7
  • 13
  • Thank you. I understand your first part, but not quite get your second part. If the largest value in R is depending on your machine. The factorial(170) is clearly bigger than my ".Machine$double.xmax." Isn't it out of number range? and also if i want ot calculate the value e.g. factorial(200), how can i do it ? – Zhe Wu Jul 26 '19 at 10:20
  • 1
    ```factorial(170)``` is ```7.257416e+306``` which is cleary smaller than ```1.797693e+308```, that you say is your ```.Machine$double.xmax```. If you write ```factorial(170) < .Machine$double.xmax``` youll see that. – Grada Gukovic Jul 26 '19 at 10:23
  • sorry, my bad the factorial(170) is smaller than 1.797693e+308. So if it is smaller, how can we calculate the factorial(180) or factorial(200)? – Zhe Wu Jul 26 '19 at 10:37
  • Just check out the post that I linked. – Grada Gukovic Jul 26 '19 at 10:39