Arithmetic-geometric mean/Calculate Pi: Difference between revisions

m
(Updated to F2008 and used iso_fortran_env, as real(16) is deprecated)
Line 744:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170680 17
1583455951826865080542496790424338362837978447536228171662934224565463064033895909488933268392567279887495006936541219489670405121434573776487989539520749180843985094860051126840117004097133550161882511486508109869673199973040182062140382647367514024790194...</pre>
 
That said, note that J offers a more direct approach here:<lang J> 102j100":<.@o.&.(*&(10^100x))1
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679</lang>
 
However, a limitation of this approach is that the floor function -- which we use here to signal the desire for an exact approximation of pi -- does not round. But we can ask for extra digits, for example:<lang J> 113j111":<.@o.&.(*&(10^111x))1
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513</lang>
 
(Another issue is that we must be careful in formatting the number to see those extra digits -- we're generating a rational number which is by default not displayed as a decimal fraction. That's what the <code>102j100":</code> bit was about -- in that example we wanted to represent the number as a decimal fraction using 102 character positions with 100 digits after the decimal point.)
 
=={{header|Java}}==
6,951

edits