diff options
-rw-r--r-- | awklib/eg/prog/pi.awk | 18 | ||||
-rw-r--r-- | doc/ChangeLog | 5 | ||||
-rw-r--r-- | doc/gawk.info | 325 | ||||
-rw-r--r-- | doc/gawk.texi | 74 | ||||
-rw-r--r-- | doc/gawktexi.in | 74 |
5 files changed, 350 insertions, 146 deletions
diff --git a/awklib/eg/prog/pi.awk b/awklib/eg/prog/pi.awk new file mode 100644 index 00000000..3297beff --- /dev/null +++ b/awklib/eg/prog/pi.awk @@ -0,0 +1,18 @@ +# pi.awk --- compute the digits of pi +# +# Katie Wasserman, katie@wass.net +# August 2014 + +BEGIN { + digits = 100000 + two = 2 * 10 ^ digits + pi = two + for (m = digits * 4; m > 0; --m) { + d = m * 2 + 1 + x = pi * m + div(x, d, result) + pi = result["quotient"] + pi = pi + two + } + print pi +} diff --git a/doc/ChangeLog b/doc/ChangeLog index 89015ce3..552ece4e 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -2,6 +2,11 @@ * gawktexi.in: More fixes after reading through the MS. + Unrelated: + + * gawktexi.in: Add Katie Wasserman's program to compute + the digits of PI. + 2014-09-30 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: More fixes after reading through the MS. diff --git a/doc/gawk.info b/doc/gawk.info index dfa21a7b..d6faeeea 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -22381,6 +22381,39 @@ user-defined function: return 0.0 } + The following example program, contributed by Katie Wasserman, uses +`div()' to compute the digits of pi to as many places as you choose to +set: + + # pi.awk --- compute the digits of pi + + BEGIN { + digits = 100000 + two = 2 * 10 ^ digits + pi = two + for (m = digits * 4; m > 0; --m) { + d = m * 2 + 1 + x = pi * m + div(x, d, result) + pi = result["quotient"] + pi = pi + two + } + print pi + } + + When asked about the algorithm used, Katie replied: + + It's not that well known but it's not that obscure either. It's + Euler's modification to Newton's method for calculating pi. Take + a look at lines (23) - (25) here: + `http://mathworld.wolfram.com/PiFormulas.htm'. + + The algorithm I wrote simply expands the multiply by 2 and works + from the innermost expression outwards. I used this to program HP + calculators because it's quite easy to modify for tiny memory + devices with smallish word sizes. See + `http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899'. + ---------- Footnotes ---------- (1) Weisstein, Eric W. `Sylvester's Sequence'. From MathWorld--A @@ -34676,151 +34709,151 @@ Node: Setting the rounding mode895668 Ref: table-gawk-rounding-modes896032 Ref: Setting the rounding mode-Footnote-1899486 Node: Arbitrary Precision Integers899665 -Ref: Arbitrary Precision Integers-Footnote-1903448 -Node: POSIX Floating Point Problems903597 -Ref: POSIX Floating Point Problems-Footnote-1907473 -Node: Floating point summary907511 -Node: Dynamic Extensions909703 -Node: Extension Intro911255 -Node: Plugin License912521 -Node: Extension Mechanism Outline913318 -Ref: figure-load-extension913746 -Ref: figure-register-new-function915226 -Ref: figure-call-new-function916230 -Node: Extension API Description918216 -Node: Extension API Functions Introduction919666 -Node: General Data Types924502 -Ref: General Data Types-Footnote-1930189 -Node: Memory Allocation Functions930488 -Ref: Memory Allocation Functions-Footnote-1933318 -Node: Constructor Functions933414 -Node: Registration Functions935148 -Node: Extension Functions935833 -Node: Exit Callback Functions938129 -Node: Extension Version String939377 -Node: Input Parsers940027 -Node: Output Wrappers949842 -Node: Two-way processors954358 -Node: Printing Messages956562 -Ref: Printing Messages-Footnote-1957639 -Node: Updating `ERRNO'957791 -Node: Requesting Values958531 -Ref: table-value-types-returned959259 -Node: Accessing Parameters960217 -Node: Symbol Table Access961448 -Node: Symbol table by name961962 -Node: Symbol table by cookie963942 -Ref: Symbol table by cookie-Footnote-1968081 -Node: Cached values968144 -Ref: Cached values-Footnote-1971648 -Node: Array Manipulation971739 -Ref: Array Manipulation-Footnote-1972837 -Node: Array Data Types972876 -Ref: Array Data Types-Footnote-1975533 -Node: Array Functions975625 -Node: Flattening Arrays979479 -Node: Creating Arrays986366 -Node: Extension API Variables991133 -Node: Extension Versioning991769 -Node: Extension API Informational Variables993670 -Node: Extension API Boilerplate994758 -Node: Finding Extensions998574 -Node: Extension Example999134 -Node: Internal File Description999906 -Node: Internal File Ops1003973 -Ref: Internal File Ops-Footnote-11015631 -Node: Using Internal File Ops1015771 -Ref: Using Internal File Ops-Footnote-11018154 -Node: Extension Samples1018427 -Node: Extension Sample File Functions1019951 -Node: Extension Sample Fnmatch1027553 -Node: Extension Sample Fork1029035 -Node: Extension Sample Inplace1030248 -Node: Extension Sample Ord1031923 -Node: Extension Sample Readdir1032759 -Ref: table-readdir-file-types1033615 -Node: Extension Sample Revout1034426 -Node: Extension Sample Rev2way1035017 -Node: Extension Sample Read write array1035758 -Node: Extension Sample Readfile1037697 -Node: Extension Sample Time1038792 -Node: Extension Sample API Tests1040141 -Node: gawkextlib1040632 -Node: Extension summary1043282 -Node: Extension Exercises1046964 -Node: Language History1047686 -Node: V7/SVR3.11049343 -Node: SVR41051524 -Node: POSIX1052969 -Node: BTL1054358 -Node: POSIX/GNU1055092 -Node: Feature History1060721 -Node: Common Extensions1073812 -Node: Ranges and Locales1075136 -Ref: Ranges and Locales-Footnote-11079775 -Ref: Ranges and Locales-Footnote-21079802 -Ref: Ranges and Locales-Footnote-31080036 -Node: Contributors1080257 -Node: History summary1085797 -Node: Installation1087166 -Node: Gawk Distribution1088122 -Node: Getting1088606 -Node: Extracting1089430 -Node: Distribution contents1091072 -Node: Unix Installation1096842 -Node: Quick Installation1097459 -Node: Additional Configuration Options1099890 -Node: Configuration Philosophy1101630 -Node: Non-Unix Installation1103981 -Node: PC Installation1104439 -Node: PC Binary Installation1105765 -Node: PC Compiling1107613 -Ref: PC Compiling-Footnote-11110634 -Node: PC Testing1110739 -Node: PC Using1111915 -Node: Cygwin1116030 -Node: MSYS1116853 -Node: VMS Installation1117351 -Node: VMS Compilation1118143 -Ref: VMS Compilation-Footnote-11119365 -Node: VMS Dynamic Extensions1119423 -Node: VMS Installation Details1121107 -Node: VMS Running1123359 -Node: VMS GNV1126200 -Node: VMS Old Gawk1126929 -Node: Bugs1127399 -Node: Other Versions1131369 -Node: Installation summary1137582 -Node: Notes1138638 -Node: Compatibility Mode1139503 -Node: Additions1140285 -Node: Accessing The Source1141210 -Node: Adding Code1142646 -Node: New Ports1148818 -Node: Derived Files1153299 -Ref: Derived Files-Footnote-11158774 -Ref: Derived Files-Footnote-21158808 -Ref: Derived Files-Footnote-31159404 -Node: Future Extensions1159518 -Node: Implementation Limitations1160124 -Node: Extension Design1161372 -Node: Old Extension Problems1162526 -Ref: Old Extension Problems-Footnote-11164043 -Node: Extension New Mechanism Goals1164100 -Ref: Extension New Mechanism Goals-Footnote-11167460 -Node: Extension Other Design Decisions1167649 -Node: Extension Future Growth1169757 -Node: Old Extension Mechanism1170593 -Node: Notes summary1172355 -Node: Basic Concepts1173541 -Node: Basic High Level1174222 -Ref: figure-general-flow1174494 -Ref: figure-process-flow1175093 -Ref: Basic High Level-Footnote-11178322 -Node: Basic Data Typing1178507 -Node: Glossary1181835 -Node: Copying1206993 -Node: GNU Free Documentation License1244549 -Node: Index1269685 +Ref: Arbitrary Precision Integers-Footnote-1904575 +Node: POSIX Floating Point Problems904724 +Ref: POSIX Floating Point Problems-Footnote-1908600 +Node: Floating point summary908638 +Node: Dynamic Extensions910830 +Node: Extension Intro912382 +Node: Plugin License913648 +Node: Extension Mechanism Outline914445 +Ref: figure-load-extension914873 +Ref: figure-register-new-function916353 +Ref: figure-call-new-function917357 +Node: Extension API Description919343 +Node: Extension API Functions Introduction920793 +Node: General Data Types925629 +Ref: General Data Types-Footnote-1931316 +Node: Memory Allocation Functions931615 +Ref: Memory Allocation Functions-Footnote-1934445 +Node: Constructor Functions934541 +Node: Registration Functions936275 +Node: Extension Functions936960 +Node: Exit Callback Functions939256 +Node: Extension Version String940504 +Node: Input Parsers941154 +Node: Output Wrappers950969 +Node: Two-way processors955485 +Node: Printing Messages957689 +Ref: Printing Messages-Footnote-1958766 +Node: Updating `ERRNO'958918 +Node: Requesting Values959658 +Ref: table-value-types-returned960386 +Node: Accessing Parameters961344 +Node: Symbol Table Access962575 +Node: Symbol table by name963089 +Node: Symbol table by cookie965069 +Ref: Symbol table by cookie-Footnote-1969208 +Node: Cached values969271 +Ref: Cached values-Footnote-1972775 +Node: Array Manipulation972866 +Ref: Array Manipulation-Footnote-1973964 +Node: Array Data Types974003 +Ref: Array Data Types-Footnote-1976660 +Node: Array Functions976752 +Node: Flattening Arrays980606 +Node: Creating Arrays987493 +Node: Extension API Variables992260 +Node: Extension Versioning992896 +Node: Extension API Informational Variables994797 +Node: Extension API Boilerplate995885 +Node: Finding Extensions999701 +Node: Extension Example1000261 +Node: Internal File Description1001033 +Node: Internal File Ops1005100 +Ref: Internal File Ops-Footnote-11016758 +Node: Using Internal File Ops1016898 +Ref: Using Internal File Ops-Footnote-11019281 +Node: Extension Samples1019554 +Node: Extension Sample File Functions1021078 +Node: Extension Sample Fnmatch1028680 +Node: Extension Sample Fork1030162 +Node: Extension Sample Inplace1031375 +Node: Extension Sample Ord1033050 +Node: Extension Sample Readdir1033886 +Ref: table-readdir-file-types1034742 +Node: Extension Sample Revout1035553 +Node: Extension Sample Rev2way1036144 +Node: Extension Sample Read write array1036885 +Node: Extension Sample Readfile1038824 +Node: Extension Sample Time1039919 +Node: Extension Sample API Tests1041268 +Node: gawkextlib1041759 +Node: Extension summary1044409 +Node: Extension Exercises1048091 +Node: Language History1048813 +Node: V7/SVR3.11050470 +Node: SVR41052651 +Node: POSIX1054096 +Node: BTL1055485 +Node: POSIX/GNU1056219 +Node: Feature History1061848 +Node: Common Extensions1074939 +Node: Ranges and Locales1076263 +Ref: Ranges and Locales-Footnote-11080902 +Ref: Ranges and Locales-Footnote-21080929 +Ref: Ranges and Locales-Footnote-31081163 +Node: Contributors1081384 +Node: History summary1086924 +Node: Installation1088293 +Node: Gawk Distribution1089249 +Node: Getting1089733 +Node: Extracting1090557 +Node: Distribution contents1092199 +Node: Unix Installation1097969 +Node: Quick Installation1098586 +Node: Additional Configuration Options1101017 +Node: Configuration Philosophy1102757 +Node: Non-Unix Installation1105108 +Node: PC Installation1105566 +Node: PC Binary Installation1106892 +Node: PC Compiling1108740 +Ref: PC Compiling-Footnote-11111761 +Node: PC Testing1111866 +Node: PC Using1113042 +Node: Cygwin1117157 +Node: MSYS1117980 +Node: VMS Installation1118478 +Node: VMS Compilation1119270 +Ref: VMS Compilation-Footnote-11120492 +Node: VMS Dynamic Extensions1120550 +Node: VMS Installation Details1122234 +Node: VMS Running1124486 +Node: VMS GNV1127327 +Node: VMS Old Gawk1128056 +Node: Bugs1128526 +Node: Other Versions1132496 +Node: Installation summary1138709 +Node: Notes1139765 +Node: Compatibility Mode1140630 +Node: Additions1141412 +Node: Accessing The Source1142337 +Node: Adding Code1143773 +Node: New Ports1149945 +Node: Derived Files1154426 +Ref: Derived Files-Footnote-11159901 +Ref: Derived Files-Footnote-21159935 +Ref: Derived Files-Footnote-31160531 +Node: Future Extensions1160645 +Node: Implementation Limitations1161251 +Node: Extension Design1162499 +Node: Old Extension Problems1163653 +Ref: Old Extension Problems-Footnote-11165170 +Node: Extension New Mechanism Goals1165227 +Ref: Extension New Mechanism Goals-Footnote-11168587 +Node: Extension Other Design Decisions1168776 +Node: Extension Future Growth1170884 +Node: Old Extension Mechanism1171720 +Node: Notes summary1173482 +Node: Basic Concepts1174668 +Node: Basic High Level1175349 +Ref: figure-general-flow1175621 +Ref: figure-process-flow1176220 +Ref: Basic High Level-Footnote-11179449 +Node: Basic Data Typing1179634 +Node: Glossary1182962 +Node: Copying1208120 +Node: GNU Free Documentation License1245676 +Node: Index1270812 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index ebaafbf3..5315422f 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -31004,6 +31004,80 @@ function div(numerator, denominator, result, i) @c endfile @end example +The following example program, contributed by Katie Wasserman, +uses @code{div()} to +compute the digits of @value{PI} to as many places as you +choose to set: + +@example +@c file eg/prog/pi.awk +# pi.awk --- compute the digits of pi +@c endfile +@c endfile +@ignore +@c file eg/prog/pi.awk +# +# Katie Wasserman, katie@@wass.net +# August 2014 +@c endfile +@end ignore +@c file eg/prog/pi.awk + +BEGIN @{ + digits = 100000 + two = 2 * 10 ^ digits + pi = two + for (m = digits * 4; m > 0; --m) @{ + d = m * 2 + 1 + x = pi * m + div(x, d, result) + pi = result["quotient"] + pi = pi + two + @} + print pi +@} +@c endfile +@end example + +@ignore +Date: Wed, 20 Aug 2014 10:19:11 -0400 +To: arnold@skeeve.com +From: Katherine Wasserman <katie@wass.net> +Subject: Re: computation of digits of pi? + +Arnold, + +>The program that you sent to compute the digits of pi using div(). Is +>that some standard algorithm that every math student knows? If so, +>what's it called? + +It's not that well known but it's not that obscure either + +It's Euler's modification to Newton's method for calculating pi. + +Take a look at lines (23) - (25) here: http://mathworld.wolfram.com/PiFormulas.htm + +The algorithm I wrote simply expands the multiply by 2 and works from the innermost expression outwards. I used this to program HP calculators because it's quite easy to modify for tiny memory devices with smallish word sizes. + +http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899 + +-Katie +@end ignore + +When asked about the algorithm used, Katie replied: + +@quotation +It's not that well known but it's not that obscure either. +It's Euler's modification to Newton's method for calculating pi. +Take a look at lines (23) - (25) here: @uref{http://mathworld.wolfram.com/PiFormulas.htm}. + +The algorithm I wrote simply expands the multiply by 2 and works from +the innermost expression outwards. I used this to program HP calculators +because it's quite easy to modify for tiny memory devices with smallish +word sizes. See +@uref{http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899}. +@end quotation + @node POSIX Floating Point Problems @section Standards Versus Existing Practice diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 96c0a76c..2600011f 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -30098,6 +30098,80 @@ function div(numerator, denominator, result, i) @c endfile @end example +The following example program, contributed by Katie Wasserman, +uses @code{div()} to +compute the digits of @value{PI} to as many places as you +choose to set: + +@example +@c file eg/prog/pi.awk +# pi.awk --- compute the digits of pi +@c endfile +@c endfile +@ignore +@c file eg/prog/pi.awk +# +# Katie Wasserman, katie@@wass.net +# August 2014 +@c endfile +@end ignore +@c file eg/prog/pi.awk + +BEGIN @{ + digits = 100000 + two = 2 * 10 ^ digits + pi = two + for (m = digits * 4; m > 0; --m) @{ + d = m * 2 + 1 + x = pi * m + div(x, d, result) + pi = result["quotient"] + pi = pi + two + @} + print pi +@} +@c endfile +@end example + +@ignore +Date: Wed, 20 Aug 2014 10:19:11 -0400 +To: arnold@skeeve.com +From: Katherine Wasserman <katie@wass.net> +Subject: Re: computation of digits of pi? + +Arnold, + +>The program that you sent to compute the digits of pi using div(). Is +>that some standard algorithm that every math student knows? If so, +>what's it called? + +It's not that well known but it's not that obscure either + +It's Euler's modification to Newton's method for calculating pi. + +Take a look at lines (23) - (25) here: http://mathworld.wolfram.com/PiFormulas.htm + +The algorithm I wrote simply expands the multiply by 2 and works from the innermost expression outwards. I used this to program HP calculators because it's quite easy to modify for tiny memory devices with smallish word sizes. + +http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899 + +-Katie +@end ignore + +When asked about the algorithm used, Katie replied: + +@quotation +It's not that well known but it's not that obscure either. +It's Euler's modification to Newton's method for calculating pi. +Take a look at lines (23) - (25) here: @uref{http://mathworld.wolfram.com/PiFormulas.htm}. + +The algorithm I wrote simply expands the multiply by 2 and works from +the innermost expression outwards. I used this to program HP calculators +because it's quite easy to modify for tiny memory devices with smallish +word sizes. See +@uref{http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899}. +@end quotation + @node POSIX Floating Point Problems @section Standards Versus Existing Practice |