[comp.lang.c] Trouble with floor

robert@csustan.UUCP (Robert Zeff) (06/12/88)

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?
thanks,



-- 
Robert Zeff                         (209) 577-4268 voice, FAX: (209) 577-8548
2549 Yosemite Blvd Ste. E           {lll-lcc,lll-crg}!csustan!zhome!robert
Modesto, Ca. 95354                  {lll-lcc,lll-crg}!csustan!robert

andrew@frip.gwd.tek.com (Andrew Klossner) (06/12/88)

> 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@relay.cs.net)   [ARPA]

haugj@pigs.UUCP (The Beach Bum) (06/14/88)

In article <1146@csustan.UUCP>, robert@csustan.UUCP (Robert Zeff) writes:
> 
> I'm having trouble with ceil () & floor ().
> I'm using a Tektronix 4301 (68020, UTEK & BSD4.3, 
> GreenHills C compiler.)

I'm running a Plexus P/95 (68020, System V, no 68881) and have the Greenhills
C compiler.  We currently have 1.8.0 of the compiler.  I haven't had any
trouble with the compiler.  I compiled the example which was given and all
seems well.

- John.
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!killer!rpp386!jfh                          jfh@rpp386.uucp :SMAILERS

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune