[futurebasic] USING bug with -0.000 input

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2011 : Group Archive : Group : All Groups

From: Walter Lenk <Walter_Lenk@...>
Date: Sun, 5 Jun 2011 15:10:25 -0400
I routinely use 'USING' for formatting numbers. Recently I discovered 
what appears to be a bug in the USING routine when it is fed with a 
value of -0.00.

Here is an example:

DIM AS SINGLE   result
DIM AS STR255   B$
B$ = USING "+#.######^^^^";result
   For result =  0.000, B$ is returned as "+0.000000E+00" < -correct
   For result = -0.000, B$ is returned as "+?.??????0000" <- WRONG

This also seems to be the case when the input is a double as well as 
a single. I tracked down the C function that is responsible for this 
conversion (PSusing), which takes a double as an argument along with 
the formatting string. At the beginning of this function, there is 
some logic that decides whether the number passed is a negative 
number or not:

	if ( n < 0.0 )
		negative = true;
		num = -n;
	} else {
		num = n;

This logic does check to ascertain whether the number is below zero 
or not, but it does not check the MSB of the float, Which is the only 
clue in the case of the value -0.00. I can write some code to trap 
out the offending case, but it would seem to be cleaner to fix the 



Walter Lenk    Cambridge Ma    617-547-7781