[comp.sys.amiga] Manx and floats

disd@hubcap.clemson.edu (BJ Backitis) (04/17/89)

I don't think this qualifies for .tech.  It's probably just a
misapprehension of either the Manx docs or the C language (or both).

Yesterday, for the first time, I decided to use floating point numbers
with the Manx compiler.  (I know, "Ick! You *want* to use floats?")
Never mind why, I just do.  Anyway  I read in the documentation that in
order to use floats, one must compile using the +f option.  +ff for FFP,
and +fi for IEEE.  Then you must link using the appropriate math
library.  (Though it isn't clear which libraries are appropriate for
which options.)  Well the docs make mention of an mx.lib.  Mx.lib
doesn't exist in my LIB directory.  The on-disk release notes say that
the mx.lib's were removed for rel 3.6a, but they don't say what is
intended to replace them.

Anyway, to my problem.  I have need to convert text of the following
sort, " 2.78 \n", to the corresponding floating point value.  "Okay", says
I, "I'll just use sscanf."  Right.  So I added something similar to the
following to my code:

char text[80];
float number;

/* We do an fgets to get the digits from a file and put them to 'text'
*/

/* Why *does* fgets return the string *plus* the newline character? */ 

/* then .... */

sscanf(text,"%f",&number);

I compiled the program using either one of the +f flags and linked using
the following:

ln -g [.o files here] -larp -l["appropriate" math lib here] -lc

Now according to SDB, text is indeed " 2.78 \n", but number does not get
converted to the floating point equivalent.  I played around with sscanf
a little using an integer variable just to see if sscanf would work with
ints.  (SDB makes for a wonderful C interpreter. :-)  It converted text
to 2 and stored it in the int variable just so.  So sscanf works as
advertised, but something needed for proper float use is missing.

Does anyone have any suggestions?  ("Buy Lattice 5.02." or "Wait for
Manx 5.0" are not acceptable suggestions. :-)  Am I using proper
procedure?  What exactly are the correct math libraries for floats?  Am
I accidentally getting a sscanf from the arp.lib?  And will Justine
divorce Brad?

Thanks,
Gary  (seasoned Amigan, seasoned programmer, apprentice C programmer)




-- 
Frank J. ("BJ") Backitis,Jr. -- Information Systems Development
(aka KB4VSW)                    Clemson University, Clemson, SC
   
Question authority ... but make sure to raise your hand first. 

disd@hubcap.clemson.edu (Gary Heffelfinger) (04/17/89)

From article <5135@hubcap.clemson.edu>, by disd@hubcap.clemson.edu (BJ Backitis):
[Dammit, I *hate* sharing an ID!]

The previous post was made by Gary Heffelfinger, *not* BJ Backitis.

Sorry.


-- 
Gary R Heffelfinger   -  disd@hubcap.clemson.edu   
"If it should become necessary to fight, could you arrange to find me
     some rocks to throw at them?"   W.T. Riker

carlos@io.UUCP (Carlos Smith x4433) (04/19/89)

In article <5135@hubcap.clemson.edu> disd@hubcap.clemson.edu (BJ Backitis) writes:
>char text[80];
>float number;
>
>/* We do an fgets to get the digits from a file and put them to 'text'
>*/
>/* Why *does* fgets return the string *plus* the newline character? */ 
>/* then .... */
>
>sscanf(text,"%f",&number);
>
>Now according to SDB, text is indeed " 2.78 \n", but number does not get
>converted to the floating point equivalent.  
>-- 
>Frank J. ("BJ") Backitis,Jr. -- Information Systems Development
>(aka KB4VSW)                    Clemson University, Clemson, SC

I use sscanf's in Manx all the time (for requesters, you know). The only thing
I do differently is that I always use *doubles*, and do the sscanf as
sscanf(text, "%lf",&number); This always works for me, for either IEEE or
Motorola FFP format.

Another question is - are you SURE the number is being scanned incorrectly?
Did you know that Manx's own SDB does not correctly interpret any floating 
point numbers that are not in IEEE format? In particular, any printing of 
floats in the Motorala Fast Floating Point (FFP) format will give garbage 
numbers in the output (another of the bugs they haven't bothered to fix...). 
It would certainly appear that they are not scanned correctly. Try a printf of 
the number to see if it is really wrong (assuming you haven't done so already).

Hope this helped...
-- 
			Carlos Smith
			uucp:...!mit-eddie!ileaf!carlos
			Bix:	carlosmith

tas@mtuxo.att.com (XMPC2-T.SKROBALA) (04/21/89)

In article <13477@louie.udel.EDU>, mermelstein@inrs-telecom.uquebec.ca (Lois Mermelstein) writes:
> 
> However, if you recompile and link, adding the options to generate info
> for SDB, and run the program with SDB, you'll discover that SDB won't
> be able to tell you the correct values of any floating point (float OR
> double) variables, structure elements, etc. (You, instead, get things
> like [lotsa digits]e-314 when the value should be 1.0.)

I, too have had problems getting SDB to print floating point values.  It
may be possible to get it to work with one of the other floating-point
models, but, in any case, there is a workaround that you may be able to
use.  Simply give sdb the command
	e printf( "%f", variable )
Assuming that your program has printf() linked in, you can use that command to
invoke a call to printf, which will send its output to the standard output.
If the standard output is your console window, you just have to take a peek
at that screen to see your variable's value.

Tom Skrobala  AT&T Bell Laboratories  att!mtuxo!tas

karl@sugar.hackercorp.com (Karl Lehenbauer) (04/22/89)

In article <5135@hubcap.clemson.edu> disd@hubcap.clemson.edu (BJ Backitis) writes:
>sscanf(text,"%f",&number);
>
>Now according to SDB, text is indeed " 2.78 \n", but number does not get
>converted to the floating point equivalent.  

You are probably scanning the number in fine and Manx SDB is lying to you
about what's in there.

Manx SDB only knows how to debug the floating point format selected by
"+fi" compiler option and linked with the "-ma" library variants, like
"ma," "mal" and "mal32."
-- 
-- uunet!sugar!karl  | "Nobody hipped me to that, dude." -- Pee Wee
-- Usenet BBS (713) 438-5018

bdb@becker.UUCP (Bruce Becker) (04/24/89)

In article <5135@hubcap.clemson.edu> disd@hubcap.clemson.edu (BJ Backitis) writes:
| [...]
|sscanf(text,"%f",&number);
|
|I compiled the program using either one of the +f flags and linked using
|the following:
|
|ln -g [.o files here] -larp -l["appropriate" math lib here] -lc
|
|Now according to SDB, text is indeed " 2.78 \n", but number does not get
|converted to the floating point equivalent.  I played around with sscanf
|a little using an integer variable just to see if sscanf would work with
|ints.  (SDB makes for a wonderful C interpreter. :-)  It converted text
|to 2 and stored it in the int variable just so.  So sscanf works as
|advertised, but something needed for proper float use is missing.

	The Manx docs are a little disordered, but the
	info is in there somewhere. What you need to do
	is add "-lm" *before* the "-lc" on the link command.
	This brings in versions of printf/scanf from the
	math library which support floating point...

Cheers,
-- 
   __	 Bruce Becker	Toronto, Ont.
w \cc/	 Internet: bdb@becker.UUCP, bruce@gpu.utcs.toronto.edu
 `/v/-e	 BitNet:   BECKER@HUMBER.BITNET
_<  >_	 "A divine sparc turned me from nextrophilia" - NoNuke of the North

ecphssrw@winston.csun.edu (Stephen Walton) (04/28/89)

In article <13477@louie.udel.EDU>, mermelstein@inrs-telecom (Lois Mermelstein) writes:
>My setup for using Manx 3.6a with floats is
>	#include <math.h> [somewhere near the top of my source code]
>	compile using cc [filename]  [no options]
>	link using ln [filename.o] -lm -lc
>
>you'll discover that SDB won't
>be able to tell you the correct values of any floating point (float OR
>double) variables...

This is because SDB was apparently compiled with the IEEE format.  Use the
+FI switch and link with -lmx or -lma.  The latter uses CBM's mathieeedoubbas-
.library, which will use a 68881 on a system with one and software without.
+F8 of course requires a 68881 and linking with -lm8 (and also works with SDB).

>I also had a problem with fscanf; I think using %e helped it, but I
>don't remember if I ever figured out *why*

Just remember (1) pass pointers to scanf and (2) if you pass a pointer to
double instead of a pointer to long, precede the conversion character by
l (that's lower-case letter ell), as in "%le" or "%lf".
--
Stephen Walton, Dept. of Physics & Astronomy, Cal State Univ. Northridge
RCKG01M@CALSTATE.BITNET       ecphssrw@afws.csun.edu
swalton@solar.stanford.edu    ...!csun!afws.csun.edu!ecphssrw