🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #2688

Manx modf() bug

#2688
From: Allan Duncan
Date: Tue, 12 Dec 1989 06:58
43 lines
1375 bytes
I've had one query WRT Manx modf bug, here's a sample prog : -


#include	<math.h>
#include	<stdio.h>


main()
{
double	n ;
double	a, x ;

while( 1 ) {
	printf( "?> " ) ;
	scanf( "%lf", &x ) ;
	a = modf( x, &n ) ;
	printf( "%lf ->  %lf & %lf\n", x, n, a ) ;
	}
}

feed it 2.1 and the answer should be 2 and 0.1 (same sign)
or -2.1 to get -2 and -0.1

If you do
	cc test.c
	ln test.o -lm -lc  (FFP)
you will find that the fraction is always incorrectly signed.
but with IEEE ( ln test.o -lma -lc) it is correct.

As an aside, I had great trouble getting this to work until I realised
that the definition of modf args given in Harbison & Steele was wrong -
	double modf(x, nptr)
		double	x ;
		int	*nptr ;

it should be	double	*nptr ;  !


Allan Duncan	ACSnet	aduncan@rhea.trl.oz
		ARPA	aduncan%rhea.trl.oz.au@uunet.uu.net
		UUCP	{uunet,hplabs,ukc}!munnari!rhea.trl.oz.au!aduncan
Telecom Research Labs, PO Box 249, Clayton, Victoria, 3168, Australia.
Technical Details
Message-ID: <872@trlluna.trl.oz>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!bruce!trlluna!rhea.trl.oz.au!aduncan

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!bruce!trlluna!rhea.trl.oz.au!aduncan
From: aduncan@rhea.trl.oz.au (Allan Duncan)
Newsgroups: comp.sys.amiga.tech
Subject: Manx modf() bug
Message-ID: <872@trlluna.trl.oz>
Date: 12 Dec 89 06:58:46 GMT
Sender: root@trlluna.trl.oz
Lines: 43