Trouble with floor ()

Andrew Klossner andrew at frip.gwd.tek.com
Sun Jun 12 12:42:54 AEST 1988


> I'm having trouble with ceil () & floor ().
> This program returns the correct values on the first loop only.
> On successive passes, floor() returns the same result as ceil().
> I'm using a Tektronix 4301 (68020, UTEK & BSD4.3, 
> GreenHills C compiler.)
> 
> #include <math.h>
> main () {
>   double value, ceil (), floor ();
>   
>   for (;;) {
>     printf ("\nInput value: ");
>     scanf ("%lf", &value);
>     printf ("\nCeiling: %lf, Floor: %lf\n", ceil (value), floor (value));
>   }
> }
> 
> Anyone else having this problem on other hardware?

Blush.  This isn't a hardware problem; it's a bug in the Tektronix
implementation of libm.  The rest of you 68881 users can breathe easy.

Thanks for pointing out this bug.  It will be corrected in an upcoming
software release.  In the meantime, you can work around by putting the
following into a shell script and executing it as root:

--------------- Cut here
chdir /tmp
cat >floor.s <<"EOF"
	.globl	_floor
_floor:
        fmove.l fpcr,d0
        move.l	d0,d1
        and.l   #0xFFFFFFF0,d0
        or.l    #0x00000020,d0
        fmove.l d0,fpcr
        fint.d  4(a7),fp0
        fmove.l d1,fpcr
	rts
EOF
cat >ceil.s <<"EOF"
	.globl	_ceil
_ceil:
        fmove.l fpcr,d0
        move.l	d0,d1
        and.l   #0xFFFFFFF0,d0
        or.l    #0x00000030,d0
        fmove.l d0,fpcr
        fint.d  4(a7),fp0
        fmove.l d1,fpcr
	rts
EOF
cat >rint.s <<"EOF"
	.globl	_rint
_rint:
        fmove.l fpcr,d0
        move.l	d0,d1
        and.l   #0xFFFFFFF0,d0
        fmove.l d0,fpcr
        fint.d  4(a7),fp0
        fmove.l d1,fpcr
	rts
EOF
as -68020 -M floor.s
as -68020 -M ceil.s
as -68020 -M rint.s
mv /usr/lib/libm.a /usr/lib/libm.a.OLD
cp /usr/lib/libm.a.OLD /usr/lib/libm.a
ar r /usr/lib/libm.a floor.o ceil.o rint.o
rm floor.s floor.o ceil.s ceil.o rint.s rint.o
--------------- Cut here

If you use profiled libraries, make similar changes to
/usr/lib/libm_p.a.

  -=- Andrew Klossner   (decvax!tektronix!tekecs!andrew)       [UUCP]
                        (andrew%tekecs.tek.com at relay.cs.net)   [ARPA]



More information about the Comp.lang.c mailing list