Calculating the Number of Digits in x

  • Thread starter soandos
  • Start date
In summary, there are multiple ways to estimate or calculate the number of digits in x!, including using Stirling's formula, the series formula, or calculating the logarithms of the terms. It ultimately depends on the size of n and the desired level of precision. Some software, such as Mathematica, may have functions to help with this calculation.
  • #1
soandos
166
0
is there a way to determine (does not need to be exact) the number of digits in x! ?

sorry if this is kind of pointless
 
Mathematics news on Phys.org
  • #2
For large n, use Stirling's formula:

n! ~ (2[pi]n)1/2 (n/e)n
 
  • #3
soandos said:
is there a way to determine (does not need to be exact) the number of digits in x! ?

O(x log x).

To be more precise, x log x - x log e + O(log x), where the base of the logarithms is the base you want to express the number.
 
  • #4
Don't forget to then apply

[tex]D = 1 + \lfloor \log_{10} \lfloor n! \rfloor \rfloor [/tex]

after that for the number of digits.
 
  • #5
Gib Z said:
Don't forget to then apply

[tex]D = 1 + \lfloor \log_{10} \lfloor n! \rfloor \rfloor [/tex]

after that for the number of digits.

If [tex]n![/tex] is hard to calculate, the series

[tex]D = 1 + \lfloor \sum^n_{i=1} \log_{10}i \rfloor[/tex]

should be easier to calculate - for integer [tex]n[/tex].
 
  • #6
Jarle said:
If [tex]n![/tex] is hard to calculate, the series

[tex]D = 1 + \lfloor \sum^n_{i=1} \log_{10}i \rfloor[/tex]

should be easier to calculate - for integer [tex]n[/tex].

Depends how large n is. If it's quite large, calculating logs for each term up to it may not be easier than using Stirlings Formula which simplifies into something that doesn't look that bad after a log anyway. But that definitely is a good idea =]
 
  • #7
Anyone know of a way to get an answer just to a certain precision in mathematica?
I do no mean truncating the answer, but more the way a person would, so for example,
1/"insert incredibly long hard to calculate mess here" as zero, or instead of getting the inside of a natural log to hundreds of decimal points, just get it to 10 or so.
is there a way to do that?
 

FAQ: Calculating the Number of Digits in x

How do I calculate the number of digits in a given number?

To calculate the number of digits in a given number, you can use the logarithm function. The formula for calculating the number of digits in a number x is log10(x) + 1. This will give you the total number of digits, including any decimal places.

What if the number has leading or trailing zeros?

If the number has leading or trailing zeros, you can use the same formula as mentioned above, but exclude the zeros from the calculation. For example, if the number is 00234, you would only count the digits 2, 3, and 4, giving you a total of 3 digits.

Is there a way to calculate the number of digits without using logarithms?

Yes, you can also calculate the number of digits in a number by converting it to a string and counting the number of characters. However, this method may not work for very large numbers or numbers with decimals.

Can I calculate the number of digits in a non-integer number?

Yes, you can use the same formula for calculating the number of digits in a non-integer number. The result will include the digits after the decimal point as well.

How can I calculate the number of digits in a negative number?

To calculate the number of digits in a negative number, you can first remove the negative sign and then use the same formula as mentioned above. The result will be the same as the number of digits in the positive version of the number.

Similar threads

Replies
3
Views
1K
Replies
11
Views
1K
Replies
4
Views
861
Replies
7
Views
1K
Replies
1
Views
808
Replies
20
Views
2K
Replies
12
Views
2K
Back
Top