diff options
-rw-r--r-- | doc/ChangeLog | 5 | ||||
-rw-r--r-- | doc/gawk.info | 345 | ||||
-rw-r--r-- | doc/gawk.texi | 19 |
3 files changed, 201 insertions, 168 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index 495bead8..b786eca3 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2012-08-14 Arnold D. Robbins <arnold@skeeve.com> + + * gawk.texi: Fixed a math bug in the chapter on multiple + precision floating point. Thanks to John Haque. + 2012-08-12 Arnold D. Robbins <arnold@skeeve.com> * gawk.texi: Merged discussion of numbers from Appendix C into diff --git a/doc/gawk.info b/doc/gawk.info index c3559f3f..498c7668 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -14157,7 +14157,20 @@ operations in your calculation. The stability and the accuracy of the computation of the constant pi in the previous example can be enhanced by using the following simple algebraic transformation: - (sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + x) + (sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + 1) + +After making this, change the program does converge to pi in under 30 +iterations: + + $ gawk -f /tmp/pi2.awk + -| 3.215390309173473 + -| 3.159659942097501 + -| 3.146086215131436 + -| 3.142714599645370 + -| 3.141873049979825 + ... + -| 3.141592653589797 + -| 3.141592653589797 There is no need to be unduly suspicious about the results from floating-point arithmetic. The lesson to remember is that @@ -28842,170 +28855,170 @@ Node: POSIX Floating Point Problems575224 Ref: POSIX Floating Point Problems-Footnote-1579049 Node: Integer Programming579087 Node: Floating-point Programming580835 -Node: Floating-point Representation586757 -Node: Floating-point Context587924 -Ref: table-ieee-formats588766 -Node: Rounding Mode590150 -Ref: table-rounding-modes590629 -Ref: Rounding Mode-Footnote-1593633 -Node: Gawk and MPFR593814 -Node: Arbitrary Precision Floats595055 -Ref: Arbitrary Precision Floats-Footnote-1597477 -Node: Setting Precision597788 -Node: Setting Rounding Mode600515 -Ref: table-gawk-rounding-modes600919 -Node: Floating-point Constants602116 -Node: Changing Precision603538 -Ref: Changing Precision-Footnote-1604938 -Node: Exact Arithmetic605112 -Node: Arbitrary Precision Integers608210 -Ref: Arbitrary Precision Integers-Footnote-1611292 -Node: Advanced Features611439 -Node: Nondecimal Data612962 -Node: Array Sorting614545 -Node: Controlling Array Traversal615242 -Node: Array Sorting Functions623479 -Ref: Array Sorting Functions-Footnote-1627153 -Ref: Array Sorting Functions-Footnote-2627246 -Node: Two-way I/O627440 -Ref: Two-way I/O-Footnote-1632872 -Node: TCP/IP Networking632942 -Node: Profiling635786 -Node: Library Functions643240 -Ref: Library Functions-Footnote-1646247 -Node: Library Names646418 -Ref: Library Names-Footnote-1649889 -Ref: Library Names-Footnote-2650109 -Node: General Functions650195 -Node: Strtonum Function651148 -Node: Assert Function654078 -Node: Round Function657404 -Node: Cliff Random Function658947 -Node: Ordinal Functions659963 -Ref: Ordinal Functions-Footnote-1663033 -Ref: Ordinal Functions-Footnote-2663285 -Node: Join Function663494 -Ref: Join Function-Footnote-1665265 -Node: Gettimeofday Function665465 -Node: Data File Management669180 -Node: Filetrans Function669812 -Node: Rewind Function673951 -Node: File Checking675338 -Node: Empty Files676432 -Node: Ignoring Assigns678662 -Node: Getopt Function680215 -Ref: Getopt Function-Footnote-1691519 -Node: Passwd Functions691722 -Ref: Passwd Functions-Footnote-1700697 -Node: Group Functions700785 -Node: Walking Arrays708869 -Node: Sample Programs710438 -Node: Running Examples711103 -Node: Clones711831 -Node: Cut Program713055 -Node: Egrep Program722900 -Ref: Egrep Program-Footnote-1730673 -Node: Id Program730783 -Node: Split Program734399 -Ref: Split Program-Footnote-1737918 -Node: Tee Program738046 -Node: Uniq Program740849 -Node: Wc Program748278 -Ref: Wc Program-Footnote-1752544 -Ref: Wc Program-Footnote-2752744 -Node: Miscellaneous Programs752836 -Node: Dupword Program754024 -Node: Alarm Program756055 -Node: Translate Program760804 -Ref: Translate Program-Footnote-1765191 -Ref: Translate Program-Footnote-2765419 -Node: Labels Program765553 -Ref: Labels Program-Footnote-1768924 -Node: Word Sorting769008 -Node: History Sorting772892 -Node: Extract Program774731 -Ref: Extract Program-Footnote-1782214 -Node: Simple Sed782342 -Node: Igawk Program785404 -Ref: Igawk Program-Footnote-1800561 -Ref: Igawk Program-Footnote-2800762 -Node: Anagram Program800900 -Node: Signature Program803968 -Node: Debugger805068 -Node: Debugging806020 -Node: Debugging Concepts806453 -Node: Debugging Terms808309 -Node: Awk Debugging810906 -Node: Sample Debugging Session811798 -Node: Debugger Invocation812318 -Node: Finding The Bug813647 -Node: List of Debugger Commands820135 -Node: Breakpoint Control821469 -Node: Debugger Execution Control825133 -Node: Viewing And Changing Data828493 -Node: Execution Stack831849 -Node: Debugger Info833316 -Node: Miscellaneous Debugger Commands837297 -Node: Readline Support842742 -Node: Limitations843573 -Node: Language History845825 -Node: V7/SVR3.1847337 -Node: SVR4849658 -Node: POSIX851100 -Node: BTL852108 -Node: POSIX/GNU852842 -Node: Common Extensions858133 -Node: Ranges and Locales859240 -Ref: Ranges and Locales-Footnote-1863844 -Node: Contributors864065 -Node: Installation868326 -Node: Gawk Distribution869220 -Node: Getting869704 -Node: Extracting870530 -Node: Distribution contents872222 -Node: Unix Installation877444 -Node: Quick Installation878061 -Node: Additional Configuration Options880023 -Node: Configuration Philosophy881500 -Node: Non-Unix Installation883842 -Node: PC Installation884300 -Node: PC Binary Installation885599 -Node: PC Compiling887447 -Node: PC Testing890391 -Node: PC Using891567 -Node: Cygwin895752 -Node: MSYS896752 -Node: VMS Installation897266 -Node: VMS Compilation897869 -Ref: VMS Compilation-Footnote-1898876 -Node: VMS Installation Details898934 -Node: VMS Running900569 -Node: VMS Old Gawk902176 -Node: Bugs902650 -Node: Other Versions906502 -Node: Notes911817 -Node: Compatibility Mode912509 -Node: Additions913292 -Node: Accessing The Source914104 -Node: Adding Code915529 -Node: New Ports921496 -Node: Dynamic Extensions925609 -Node: Internals927049 -Node: Plugin License935871 -Node: Loading Extensions936509 -Node: Sample Library938348 -Node: Internal File Description939038 -Node: Internal File Ops942753 -Ref: Internal File Ops-Footnote-1947495 -Node: Using Internal File Ops947635 -Node: Future Extensions950012 -Node: Basic Concepts952516 -Node: Basic High Level953197 -Ref: Basic High Level-Footnote-1957232 -Node: Basic Data Typing957417 -Node: Glossary960772 -Node: Copying985748 -Node: GNU Free Documentation License1023305 -Node: Index1048442 +Node: Floating-point Representation587060 +Node: Floating-point Context588227 +Ref: table-ieee-formats589069 +Node: Rounding Mode590453 +Ref: table-rounding-modes590932 +Ref: Rounding Mode-Footnote-1593936 +Node: Gawk and MPFR594117 +Node: Arbitrary Precision Floats595358 +Ref: Arbitrary Precision Floats-Footnote-1597780 +Node: Setting Precision598091 +Node: Setting Rounding Mode600818 +Ref: table-gawk-rounding-modes601222 +Node: Floating-point Constants602419 +Node: Changing Precision603841 +Ref: Changing Precision-Footnote-1605241 +Node: Exact Arithmetic605415 +Node: Arbitrary Precision Integers608513 +Ref: Arbitrary Precision Integers-Footnote-1611595 +Node: Advanced Features611742 +Node: Nondecimal Data613265 +Node: Array Sorting614848 +Node: Controlling Array Traversal615545 +Node: Array Sorting Functions623782 +Ref: Array Sorting Functions-Footnote-1627456 +Ref: Array Sorting Functions-Footnote-2627549 +Node: Two-way I/O627743 +Ref: Two-way I/O-Footnote-1633175 +Node: TCP/IP Networking633245 +Node: Profiling636089 +Node: Library Functions643543 +Ref: Library Functions-Footnote-1646550 +Node: Library Names646721 +Ref: Library Names-Footnote-1650192 +Ref: Library Names-Footnote-2650412 +Node: General Functions650498 +Node: Strtonum Function651451 +Node: Assert Function654381 +Node: Round Function657707 +Node: Cliff Random Function659250 +Node: Ordinal Functions660266 +Ref: Ordinal Functions-Footnote-1663336 +Ref: Ordinal Functions-Footnote-2663588 +Node: Join Function663797 +Ref: Join Function-Footnote-1665568 +Node: Gettimeofday Function665768 +Node: Data File Management669483 +Node: Filetrans Function670115 +Node: Rewind Function674254 +Node: File Checking675641 +Node: Empty Files676735 +Node: Ignoring Assigns678965 +Node: Getopt Function680518 +Ref: Getopt Function-Footnote-1691822 +Node: Passwd Functions692025 +Ref: Passwd Functions-Footnote-1701000 +Node: Group Functions701088 +Node: Walking Arrays709172 +Node: Sample Programs710741 +Node: Running Examples711406 +Node: Clones712134 +Node: Cut Program713358 +Node: Egrep Program723203 +Ref: Egrep Program-Footnote-1730976 +Node: Id Program731086 +Node: Split Program734702 +Ref: Split Program-Footnote-1738221 +Node: Tee Program738349 +Node: Uniq Program741152 +Node: Wc Program748581 +Ref: Wc Program-Footnote-1752847 +Ref: Wc Program-Footnote-2753047 +Node: Miscellaneous Programs753139 +Node: Dupword Program754327 +Node: Alarm Program756358 +Node: Translate Program761107 +Ref: Translate Program-Footnote-1765494 +Ref: Translate Program-Footnote-2765722 +Node: Labels Program765856 +Ref: Labels Program-Footnote-1769227 +Node: Word Sorting769311 +Node: History Sorting773195 +Node: Extract Program775034 +Ref: Extract Program-Footnote-1782517 +Node: Simple Sed782645 +Node: Igawk Program785707 +Ref: Igawk Program-Footnote-1800864 +Ref: Igawk Program-Footnote-2801065 +Node: Anagram Program801203 +Node: Signature Program804271 +Node: Debugger805371 +Node: Debugging806323 +Node: Debugging Concepts806756 +Node: Debugging Terms808612 +Node: Awk Debugging811209 +Node: Sample Debugging Session812101 +Node: Debugger Invocation812621 +Node: Finding The Bug813950 +Node: List of Debugger Commands820438 +Node: Breakpoint Control821772 +Node: Debugger Execution Control825436 +Node: Viewing And Changing Data828796 +Node: Execution Stack832152 +Node: Debugger Info833619 +Node: Miscellaneous Debugger Commands837600 +Node: Readline Support843045 +Node: Limitations843876 +Node: Language History846128 +Node: V7/SVR3.1847640 +Node: SVR4849961 +Node: POSIX851403 +Node: BTL852411 +Node: POSIX/GNU853145 +Node: Common Extensions858436 +Node: Ranges and Locales859543 +Ref: Ranges and Locales-Footnote-1864147 +Node: Contributors864368 +Node: Installation868629 +Node: Gawk Distribution869523 +Node: Getting870007 +Node: Extracting870833 +Node: Distribution contents872525 +Node: Unix Installation877747 +Node: Quick Installation878364 +Node: Additional Configuration Options880326 +Node: Configuration Philosophy881803 +Node: Non-Unix Installation884145 +Node: PC Installation884603 +Node: PC Binary Installation885902 +Node: PC Compiling887750 +Node: PC Testing890694 +Node: PC Using891870 +Node: Cygwin896055 +Node: MSYS897055 +Node: VMS Installation897569 +Node: VMS Compilation898172 +Ref: VMS Compilation-Footnote-1899179 +Node: VMS Installation Details899237 +Node: VMS Running900872 +Node: VMS Old Gawk902479 +Node: Bugs902953 +Node: Other Versions906805 +Node: Notes912120 +Node: Compatibility Mode912812 +Node: Additions913595 +Node: Accessing The Source914407 +Node: Adding Code915832 +Node: New Ports921799 +Node: Dynamic Extensions925912 +Node: Internals927352 +Node: Plugin License936174 +Node: Loading Extensions936812 +Node: Sample Library938651 +Node: Internal File Description939341 +Node: Internal File Ops943056 +Ref: Internal File Ops-Footnote-1947798 +Node: Using Internal File Ops947938 +Node: Future Extensions950315 +Node: Basic Concepts952819 +Node: Basic High Level953500 +Ref: Basic High Level-Footnote-1957535 +Node: Basic Data Typing957720 +Node: Glossary961075 +Node: Copying986051 +Node: GNU Free Documentation License1023608 +Node: Index1048745 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 672b6f34..40b85aae 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -18955,9 +18955,24 @@ in the previous example can be enhanced by using the following simple algebraic transformation: @example -(sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + x) +(sqrt(x * x + 1) - 1) / x = x / (sqrt(x * x + 1) + 1) +@end example + +@noindent +After making this, change the program does converge to +@value{PI} in under 30 iterations: + +@example +$ @kbd{gawk -f /tmp/pi2.awk} +@print{} 3.215390309173473 +@print{} 3.159659942097501 +@print{} 3.146086215131436 +@print{} 3.142714599645370 +@print{} 3.141873049979825 +@dots{} +@print{} 3.141592653589797 +@print{} 3.141592653589797 @end example -@c FIXME: Show new program and results There is no need to be unduly suspicious about the results from floating-point arithmetic. The lesson to remember is that |