[net.lang.c] Help with BDSC float

moore@mit-eddie.MIT.EDU (Andrew M. Moore) (09/13/86)

   My BDS C compiler doesn't want to accept  %6.3f  (example) in printf's.
Nor does it accept "float" as a data type declaration.  On some compilers,
I don't have to declare a variable as "float" before using it:

	printf("Float: %6.3f", (5.0/4.0));

...but in BDS, this is not accepted.  How is "float" different in BDS C?

Andrew Moore
arpa MOORE%MIT-EECS@MIT-MC.ARPA
uucp ...mit-eddie!moore
  us Box 121, North Quincy, MA  02171

mdapoz@watrose.UUCP (Mark Dapoz) (09/14/86)

In article <3211@mit-eddie.MIT.EDU> moore@mit-eddie.MIT.EDU (Andrew M. Moore) writes:
>   My BDS C compiler doesn't want to accept  %6.3f  (example) in printf's.
>Nor does it accept "float" as a data type declaration.  On some compilers,
>I don't have to declare a variable as "float" before using it:
>
>	printf("Float: %6.3f", (5.0/4.0));
>
>...but in BDS, this is not accepted.  How is "float" different in BDS C?

   BDS C 1.5 does NOT support the float data type.  If you want to use floating
point arithmetic then you must use an additional library of functions called
float.c.  It's public domain and found on most RCP/M's.  I've heard rumour that
BDS C (2.0?) has floating point arithmetic and is much more K&R standard.
You'll have to check with the author to see if this is true though.
   Mark Dapoz

bert@infoswx.UUCP (09/16/86)

About float in BDSC. (I'm talking about the CPM version that I have used)

Basically, BDSC does not have float.  There is a library of float
functions available that will allow you to do some floating point
operations with some difficulty.  To use them, you must declare a 5 char
array for each float variable.  You assign it a value with a function.
You play with it with other functions.  Then you can print it with
a special printf routine that you must link in specifically to handle
the %e and %f control strings.  But don't try to use fprintf if you
link the float printf stuff in, it doesn't work on the version I have.

examples:

char float1[5], float2[5];
buf[30];

atof(float1, "10.0");        /* set float to 10.0 */

fpadd(float1, float1, atof(float2, "5.0");     /* add 5 to it */

fpsub(float1, float1, atof(float2, "2.0");     /* subtract 2 from it */

fpmult(float1, float1, float2);			/* multiply it by 5 */

fpdiv(float1, float1, float2);			/* divide it by 5 */

ftoa(buf, float1);				/* make ascii (%e format) */

printf("%f %s\n", float1, buf);				/* print it (%f, %e) */

Note that the result is left in the first arg on all the arith operations.
Also, they all return char * to the result.

Bert Campbell.

karl@haddock (09/19/86)

mit-eddie!moore (Andrew Moore) writes:
>My BDS C compiler doesn't want to accept  %6.3f  (example) in printf's.
>Nor does it accept "float" as a data type declaration.  On some compilers,
>I don't have to declare a variable as "float" before using it:
>    printf("Float: %6.3f", (5.0/4.0));

I don't understand your last sentence.  Declare what variable?  I presume
you mean that on some compilers, you can write floating-point expressions
without the keyword "float".

>...but in BDS, this is not accepted.  How is "float" different in BDS C?

The most likely answer is simply that you have a compiler that doesn't
support floating point.  (I presume "double" doesn't work either?)  Talk to
your vendor.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint