Jump to content

Pathological floating point problems: Difference between revisions

m
→‎The Chaotic Bank Society: increased decimal digits, included more information in the output section, added more wording to the REXX section header..
(Adding Fōrmulæ)
m (→‎The Chaotic Bank Society: increased decimal digits, included more information in the output section, added more wording to the REXX section header..)
Line 2,238:
 
===The Chaotic Bank Society===
To be truly accurate, the number of decimal digits for &nbsp; <big> ''' ''e'' ''' </big> &nbsp; (theshould &nbsp;have ''$''as &nbsp;many variabledecimal firstdigits value)as &nbsp;given shouldon have 150 decimalthe
<br>digitscommand &nbsp;line (or whatever isif specified), &nbsp; as per the &nbsp; '''digs''' &nbsp; REXX variable's value, but what's currently coded will suffice for the (default) number of years.
 
<br>for the (default) number of years. &nbsp; However, it makes a difference computing the balance after sixty-five years
However, it makes a difference computing the balance &nbsp; (with 341 decimal digits) &nbsp; after &nbsp; '''183''' &nbsp; years &nbsp; (when at
<br>(when at that point, &nbsp; the balance becomes negative and grows increasing negative fast).
 
With 150 decimal digits, the balance becomes negative after &nbsp; '''96''' &nbsp; years.
<lang rexx>/*REXX pgm (pathological FP problem): the chaotic bank society offering a new investment*/
e=2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713,
||8217852516642742746639193200305992181741359662904357290033429526059563073813232862794,
||3490763233829880753195251019011573834187930702154089149934884167509244761460668082264,
||8001684774118537423454424371075390777449920695517027618386062613313845830007520449338
d = length(e) - 1 /*subtract unity for the decimal point.*/
parse arg digs show y . /*obtain optional arguments from the CL*/
if digs=='' | digs=="," then digs=150 d /*Not specified? Then use the default.*/
if show=='' | show=="," then show= 20 /* " " " " " " */
if y=='' | y=="," then y= 25 /* " " " " " " */
numeric digits digs /*have REXX use "digs" decimal digits. */
$=$ e - 1 /*and subtract one$1 'causefrom e, that's that. */ /* [↑] 150 decimal digits of e da deposit*/
$=2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526
$=$ - 1 /*and subtract one 'cause that's that. */ /* [↑] 150 decimal digits of e */
/* [↑] value of newly opened account. */
do n=1 for y /*compute the value of the account/year*/
$= $*n - 1 1 /* " " " " " account now.*/
end /*n*/
@baf@@= 'BalanceWith after' d " decimal digits, the balance after " y /*display SHOW' digitsyears pastis: the dec. pt.*/'
say @baf@@ y "years: '$"'format($, , show) / 1 /*stick a fork in it, we're all done. */</lang>
'''{{out|output''' |text=&nbsp; when using the default inputs:}}
<pre>
BalanceWith 341 decimal digits, the balance after 25 years is: $0.03993872967323020890399387296732302
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.