Deutsch   English   Français   Italiano  
<0c72aa3f18201b4672ed0fc3500bd236@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.tomockey.net!2.eu.feeder.erje.net!feeder.erje.net!news.quux.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth
Subject: Re: Operator =?UTF-8?B?b3ZlcmxvYWRpbmc/?=
Date: Thu, 25 Jul 2024 09:06:03 +0000
Organization: novaBBS
Message-ID: <0c72aa3f18201b4672ed0fc3500bd236@www.novabbs.com>
References: <a1aab44ee3b1b56c2f54f2606e98d040@www.novabbs.com> <pzvvwo76lx5kh.fsf@barkhauseninstitut.org> <698bd09c6db27738ab6a1c3222aba1e1@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="290845"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="t0bSWFIQDvYvkkhDiPIIv6byulC6WbSEwXWMJpxc4k0";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$f4S0qcpi6GkJU/UNSDA6b.kBxfVRz39JPc4i9tOIXAf18JbBAhxCy
X-Rslight-Posting-User: 59549e76d0c3560fb37b97f0b9407a8c14054f24
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3112
Lines: 77

DO you mean something like the below? The code stays the
same but it is possible to choose a different type of
variable (from BYTE to arbitrary precision).

-marcel

(*
 * LANGUAGE    : ANS Forth with extensions
 * PROJECT     : Forth Environments
 * DESCRIPTION : Hairy floating-point issues
 * CATEGORY    : Demonstration, using of OPG (see also archimedes.frt)
 * AUTHOR      : Marcel Hendrix
 * LAST CHANGE : August 4, 2012, Marcel Hendrix
 * LAST CHANGE : Saturday, December 22, 2012, 22:46, Marcel Hendrix
 *)


	NEEDS -xopg

	REVISION -archimedes "--- Archimedes' PI      Version 2.01 ---"

	PRIVATES

DOC
(*
	Round-off error can affect the convergence and accuracy of iterative
	numerical procedures. As an example, Archimedes approximated PI by
	calculating the perimeters of polygons inscribing and circumscribing
	a circle, starting with hexagons, and successively doubling the number
	of sides. As noted above, computations may be rearranged in a way that
	is mathematically equivalent but less prone to error (numerical
analysis).
	Two forms of the recurrence formula for the circumscribed polygon are:

	 t0 = 1 / sqrt(3)

	 		     sqrt(ti^2+1) - 1
	 first form:  ti+1 = ----------------
				   ti

	 		     	   ti
	 second form: ti+1 = ----------------
			     sqrt(ti^2+1) + 1

*)
ENDDOC

\ .xfloat.p
 .arbitrary.p

: #SHOW ( -- )
	0-VALUE        GLOCAL t0
	PI-VALUE       GLOCAL pi
	LET SQRT(1/3): GLOCAL ti1
	LET SQRT(1/3): GLOCAL ti2

	#129 0 DO
		  I #15 AND
		  0= IF
		  	CR I 3 .R SPACE
			   LET t0=6*ti1*2^DOUBLE[I]:
			   LET (t0-PI,t0): .PRINT ."  (err=" .PRINT ." )"
		  	CR 4 SPACES
			   LET t0=6*ti2*2^DOUBLE[I]:
			   LET (t0-PI,t0): .PRINT ."  (err=" .PRINT ." )"
		  ENDIF
		  LET ti1 = (SQRT(ti1*ti1+1)-1)/ti1:
		  LET ti2 = ti2/(SQRT(ti2*ti2+1)+1):
	     LOOP ;

:ABOUT	CR ." Try: #SHOW -- approximates PI using two different
algorithms."
	CR ."      PI = " PI-VALUE .PRINT ;

		.ABOUT -archimedes CR
		DEPRIVE

                              (* End of Source *)