🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #127

bug in mpfr-3.1.0

#127
From: marcel hendrix
Date: Sun, 18 Oct 2026 16:42
86 lines
3858 bytes
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  @.Inf@e-0003 ok
FORTH> LET (2,2):  F#** .print  @.Inf@e-0001 ok
FORTH> LET (3,2):  F#** .print
9.0000000000000000000000000000000000000000e+0000 ok
FORTH> LET (4,2):  F#** .print  @.Inf@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 *)
Technical Details
Message-ID: <11b2su5$229je$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: marcel hendrix <mhx@iae.nl>
Newsgroups: comp.lang.forth
Subject: bug in mpfr-3.1.0
Date: Sun, 18 Oct 2026 18:42:43 +0200
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <11b2su5$229je$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 18 Oct 2026 16:42:46 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2172526"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18BkiRJWA8PvR0sRkh3bpiiKgeqfiF50qM="; posting-host="f2adaf6d8eda67b580e1130b162cfdc5"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0S1M8Ufm98i8KVX+2+VB4+imAr0= sha256:DTjrhj4ftlwMki/wKqTKW2vvmf1l0CxeM7VpZmWK2js=
	sha1:Z/R93CzKUUrkv9uAwaB5BNOuJD0= sha256:8PCSxZOOEWJTV41pWC1vzeAcWQ/ND0a/FdKod6TSO8w=
Content-Language: en-US