Re: Operator overloading?

Liste des GroupesRevenir à cl forth 
Sujet : Re: Operator overloading?
De : mhx (at) *nospam* iae.nl (mhx)
Groupes : comp.lang.forth
Date : 25. Jul 2024, 10:06:03
Autres entêtes
Organisation : novaBBS
Message-ID : <0c72aa3f18201b4672ed0fc3500bd236@www.novabbs.com>
References : 1 2 3
User-Agent : Rocksolid Light
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 *)

Date Sujet#  Auteur
25 Jul 24 * Operator overloading?78minforth
25 Jul 24 +- Re: Operator overloading?1dxf
25 Jul 24 +* Re: Operator overloading?18Michael Raitza
25 Jul 24 i`* Re: Operator overloading?17minforth
25 Jul 24 i +* Re: Operator overloading?5mhx
25 Jul 24 i i`* Re: Operator overloading?4minforth
26 Jul 24 i i `* Re: Operator overloading?3minforth
26 Jul 24 i i  `* Re: Operator overloading?2mhx
26 Jul 24 i i   `- Re: Operator overloading?1minforth
25 Jul 24 i `* Re: Operator overloading?11Anton Ertl
25 Jul 24 i  +* Re: Operator overloading?2minforth
30 Jul 24 i  i`- Re: Operator overloading?1Ruvim
27 Jul 24 i  `* Re: Operator overloading?8minforth
27 Jul 24 i   `* Re: Operator overloading?7Anton Ertl
27 Jul 24 i    +* Re: Operator overloading?4minforth
30 Jul 24 i    i+- quotations and closures (was: Operator overloading?)1Ruvim
1 Aug 24 i    i`* Re: Operator overloading?2Anton Ertl
1 Aug 24 i    i `- Re: Operator overloading?1minforth
27 Jul 24 i    `* Re: Operator overloading?2albert
29 Jul 24 i     `- Re: Operator overloading?1minforth
26 Jul 24 +- Re: Operator overloading?1Jan Coombs
30 Jul 24 `* Re: Operator overloading?57Stephen Pelc
30 Jul 24  +* Re: Operator overloading?3minforth
30 Jul 24  i+- Re: Operator overloading?1Stephen Pelc
1 Aug 24  i`- Re: Operator overloading?1Anton Ertl
31 Jul 24  `* Re: Operator overloading?53albert
31 Jul 24   `* Re: Operator overloading?52Gerry Jackson
31 Jul 24    +* Re: Operator overloading?50mhx
31 Jul 24    i+* Re: Operator overloading?3minforth
31 Jul 24    ii`* Re: Operator overloading?2mhx
31 Jul 24    ii `- Re: Operator overloading?1mhx
31 Jul 24    i+* VALUE and TO implementation (was: Operator overloading?)45Ruvim
31 Jul 24    ii+* Re: VALUE and TO implementation (was: Operator overloading?)41Anton Ertl
1 Aug 24    iii`* Re: VALUE and TO implementation40Ruvim
1 Aug 24    iii `* Re: VALUE and TO implementation39Anton Ertl
2 Aug 24    iii  `* Re: VALUE and TO implementation38Ruvim
3 Aug 24    iii   +* Re: VALUE and TO implementation35minforth
3 Aug 24    iii   i+* Re: VALUE and TO implementation33Ruvim
3 Aug 24    iii   ii`* Re: VALUE and TO implementation32minforth
4 Aug 24    iii   ii `* Re: VALUE and TO implementation31Ruvim
4 Aug 24    iii   ii  `* Re: VALUE and TO implementation30mhx
4 Aug 24    iii   ii   +* Re: VALUE and TO implementation4Paul Rubin
4 Aug 24    iii   ii   i+* Re: VALUE and TO implementation2mhx
4 Aug 24    iii   ii   ii`- Re: VALUE and TO implementation1Ruvim
4 Aug 24    iii   ii   i`- Re: VALUE and TO implementation1Ruvim
4 Aug 24    iii   ii   +- Re: VALUE and TO implementation1Anton Ertl
4 Aug 24    iii   ii   +* Alternative for long parsing words (was: VALUE and TO implementation)9Ruvim
5 Aug 24    iii   ii   i`* Re: Alternative for long parsing words (was: VALUE and TO implementation)8albert
5 Aug 24    iii   ii   i `* Re: Alternative for long parsing words7Ruvim
5 Aug 24    iii   ii   i  +* Re: Alternative for long parsing words5Anton Ertl
6 Aug 24    iii   ii   i  i+* Re: Alternative for long parsing words2Ruvim
6 Aug 24    iii   ii   i  ii`- Re: Alternative for long parsing words1mhx
6 Aug 24    iii   ii   i  i`* Re: Alternative for long parsing words2Ruvim
9 Aug 24    iii   ii   i  i `- Re: Alternative for long parsing words1Ruvim
6 Aug 24    iii   ii   i  `- Re: Alternative for long parsing words1albert
5 Aug 24    iii   ii   +- Re: VALUE and TO implementation1Stephen Pelc
5 Aug 24    iii   ii   `* Re: VALUE and TO implementation14dxf
5 Aug 24    iii   ii    `* Re: VALUE and TO implementation13mhx
5 Aug 24    iii   ii     +* Re: VALUE and TO implementation10dxf
5 Aug 24    iii   ii     i`* Re: VALUE and TO implementation9Ruvim
6 Aug 24    iii   ii     i `* Re: VALUE and TO implementation8dxf
7 Aug 24    iii   ii     i  `* Re: VALUE and TO implementation7dxf
7 Aug 24    iii   ii     i   +* Re: VALUE and TO implementation3Anton Ertl
7 Aug 24    iii   ii     i   i+- Re: VALUE and TO implementation1dxf
7 Aug 24    iii   ii     i   i`- Interpretation semantics (was: VALUE and TO implementation)1Ruvim
7 Aug 24    iii   ii     i   `* Re: VALUE and TO implementation3albert
7 Aug 24    iii   ii     i    `* Re: VALUE and TO implementation2Paul Rubin
8 Aug 24    iii   ii     i     `- Re: VALUE and TO implementation1albert
5 Aug 24    iii   ii     `* Re: VALUE and TO implementation2Anton Ertl
6 Aug 24    iii   ii      `- Re: VALUE and TO implementation1albert
3 Aug 24    iii   i`- Re: VALUE and TO implementation1Anton Ertl
3 Aug 24    iii   `* Re: VALUE and TO implementation2mhx
4 Aug 24    iii    `- Re: VALUE and TO implementation1Ruvim
1 Aug 24    ii+* Re: VALUE and TO implementation2minforth
2 Aug 24    iii`- Re: VALUE and TO implementation1albert
1 Aug 24    ii`- Re: VALUE and TO implementation1Ruvim
31 Jul 24    i`- Re: Operator overloading?1Gerry Jackson
31 Jul 24    `- Re: Operator overloading?1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal