[comp.sys.amiga.programmer] SAS/C : -f8 + float + scanf = garbage

hjj@athena.mit.edu (Hector Jimenez-Gonzalez) (04/04/91)

 I have the following problem with SAS/C V5.10: whenever I use the -f8 option 
of "lc" (in order to use the M68881 coprocessor for floating point 
calculations)  and the object used in the "fscanf" or "scanf" is declared as a 
float the value is read in incorrectly. If instead of float I use double 
everything works correctly. As an illustration of this problem look at this 
little program:

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

main()
{

      float v;

      while(scanf("%f", &v) == 1)
	    printf("\t%f\n",v);
}

if this is now compiled with lc -f8 -Lm , the printed value does not 
correspond to the input. Changing float to double and %f to %lf in 
"scanf" the problem goes away. 

Has anyone else noticed this problem? If not, could this be harware related?
(I am using an A2500/20).


Hector Jimenez
hjj@athena.mit.edu

markv@kuhub.cc.ukans.edu (04/08/91)

In article <1991Apr3.220228.24727@athena.mit.edu>, hjj@athena.mit.edu (Hector Jimenez-Gonzalez) writes:
> 
> I have the following problem with SAS/C V5.10: whenever I use the -f8 option 
> of "lc" (in order to use the M68881 coprocessor for floating point 
>calculations)  and the object used in the "fscanf" or "scanf" is declared as a
> float the value is read in incorrectly. If instead of float I use double 
> everything works correctly. As an illustration of this problem look at this 
> little program:
> 
>       float v;
> 
>       while(scanf("%f", &v) == 1)
> 	    printf("\t%f\n",v);
> }
> if this is now compiled with lc -f8 -Lm , the printed value does not 

Well, one problem is you are telling the compiler to link with the standard
math library, although you've got 881 support in the object file, try:

	lc -f8 -Lm881

to get the correct library.  It may be that SAS/Lattice "promotes" 
parameters differently or changes the default size of float with 881 support.

> Hector Jimenez
> hjj@athena.mit.edu
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  mgooderum	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~