iForth uses the mpfr 3.1.0 release, and possibly other Forths do too. I have found that the mpfr_pow(rop, op1,op2,roundingmode) function does not work for at least *some* values of op1 (0 and 1 works) that are a power of 2 (0 and 1 work). The source hints at this, the documentation does not.
FORTH> LET (3,2): F#** .print 9.0000000000000000000000000000000000000000e+0000 ok
FORTH> LET (1,2): F#** .print
1.0000000000000000000000000000000000000000e+0000 ok
FORTH> LET (2,3): F#** .print @.I…@e-0003 ok
FORTH> LET (2,2): F#** .print @.I…@e-0001 ok
FORTH> LET (3,2): F#** .print
9.0000000000000000000000000000000000000000e+0000 ok
FORTH> LET (4,2): F#** .print @.I…@e-0001 ok
This was found when testing the archimedes.frt program in the current iForth distribution.
-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(1+ti^2) - 1
first form: ti+1 = ----------------
ti
ti
second form: ti+1 = ----------------
sqrt(1+ti^2) + 1
*)
ENDDOC
.arbitrary.p
: #SHOW ( -- )
0-VALUE GLOCAL t0
LET SQRT(1/3): GLOCAL ti1
LET SQRT(1/3): GLOCAL ti2
CR ." flawed correct"
#32 0 DO
CR I 3 .R SPACE LET t0=6*ti1*2^double(I()): LET (t0-PI,t0): .PRINT ." (err=" .PRINT ." )"
4 SPACES LET t0=6*ti2*2^double(I()): LET (t0-PI,t0): .PRINT ." (err=" .PRINT ." )"
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 *)
bug in mpfr-3.1.0
- From
- marcel hendrix <m…@iae.nl>
- Organization
- A noiseless patient Spider
- Message-ID
- <11b2…@dont-email.me>
- Date
- Newsgroups
- comp.lang.forth