Home  >  Article  >  Web Front-end  >  How to use JS to calculate pi to 100 decimal places

How to use JS to calculate pi to 100 decimal places

php中世界最好的语言
php中世界最好的语言Original
2018-05-31 09:41:262341browse

This time I will show you how to use JS to calculate pi to 100 digits after the decimal point, and how to use JS to calculate pi to 100 digits after the decimal point. What are the precautions? What are the practical cases below? take a look.

The significant digits of floating point numbers are 16. I made a large number class myself, which can store 100 significant digits and implement the basic operations of the large number class. I used it to calculate pi (circle cut method, that is, polygonal approximation), and got one hundred significant figures after the decimal point. I compared the calculation results with Machin's formula, and there was no error. It takes about 2 seconds.

The complete example is as follows:





 js计算圆周率

Running result:

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421 170679

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to php Other related articles on the Chinese website!

Recommended reading:

JS commonly used algorithms accumulation, iteration, exhaustion, recursive implementation (with code)

##JS Detailed explanation of the steps to use the callback function

The above is the detailed content of How to use JS to calculate pi to 100 decimal places. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn