?? pi.txt
字號:
This file describes how pi is computed by the program in 'pi.c' (seethe utils subdirectory).Basically, we use Machin's formula, which is what everyone in theworld uses as a simple method for computing approximations to pi.This works for up to a few thousand digits without too much effort.Beyond that, though, it gets too slow.Machin's formula states: pi := 16 * arctan(1/5) - 4 * arctan(1/239)We compute this in integer arithmetic by first multiplying everythingthrough by 10^d, where 'd' is the number of digits of pi we wanted tocompute. It turns out, the last few digits will be wrong, but thenumber that are wrong is usually very small (ordinarly only 2-3).Having done this, we compute the arctan() function using the formula: 1 1 1 1 1 arctan(1/x) := --- - ----- + ----- - ----- + ----- - ... x 3 x^3 5 x^5 7 x^7 9 x^9This is done iteratively by computing the first term manually, andthen iteratively dividing x^2 and k, where k = 3, 5, 7, ... out of thecurrent figure. This is then added to (or subtracted from) a runningsum, as appropriate. The iteration continues until we overflow ouravailable precision and the current figure goes to zero under integerdivision. At that point, we're finished.Actually, we get a couple extra bits of precision out of the fact thatwe know we're computing y * arctan(1/x), by setting up the multiplieras: y * 10^d... instead of just 10^d. There is also a bit of cleverness in howthe loop is constructed, to avoid special-casing the first term.Check out the code for arctan() in 'pi.c', if you are interested inseeing how it is set up.Thanks to Jason P. for this algorithm, which I assembled from notesand programs found on his cool "Pile of Pi Programs" page, at: http://www.isr.umd.edu/~jasonp/pipage.htmlThanks also to Henrik Johansson <Henrik.Johansson@Nexus.Comm.SE>, fromwhose pi program I borrowed the clever idea of pre-multiplying by x inorder to avoid a special case on the loop iteration.------------------------------------------------------------------The contents of this file are subject to the Mozilla PublicLicense Version 1.1 (the "License"); you may not use this fileexcept in compliance with the License. You may obtain a copy ofthe License at http://www.mozilla.org/MPL/Software distributed under the License is distributed on an "ASIS" basis, WITHOUT WARRANTY OF ANY KIND, either express orimplied. See the License for the specific language governingrights and limitations under the License.The Original Code is the MPI Arbitrary Precision Integer Arithmeticlibrary.The Initial Developer of the Original Code is Michael J. Fromberger <sting@linguist.dartmouth.edu>Portions created by Michael J. Fromberger are Copyright (C) 1998, 2000 Michael J. Fromberger. All Rights Reserved.Contributor(s):Alternatively, the contents of this file may be used under theterms of the GNU General Public License Version 2 or later (the"GPL"), in which case the provisions of the GPL are applicableinstead of those above. If you wish to allow use of yourversion of this file only under the terms of the GPL and not toallow others to use your version of this file under the MPL,indicate your decision by deleting the provisions above andreplace them with the notice and other provisions required bythe GPL. If you do not delete the provisions above, a recipientmay use your version of this file under either the MPL or the GPL.$Id: pi.txt,v 1.1 2000/07/14 00:44:35 nelsonb%netscape.com Exp $
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -