I assume it is an intentional undocumented change and not a bug: FloatToString now outputs string in exponential format for numbers with an absolute value less than 1.0. (like 2.342536 e-1) instead of the fixed decimal places in the previous version. This really broke my LCD output routines which I designed to truncate part of the decimals to fit to the limited space on the LCD.
Also, because of this truncation I use, it was not easy to figure out what was going on firmware/hardware vise, since the exponential was not displayed in the output....
I do think the compilers are getting to the stage of maturity where one need to consider stability of code in the sense that new versions do not break old code because things like procedure calls and results are changed back and forth. For instance, if I had been a company maintaining a portfolio of instruments with different firmware, it would be very bothersome if code for all the instruments had to be changed with every new compiler version.
That said, would it be possible to get the old FloatToString back ,
or could we get two versions of the procedure, one with exponential and one which always use fixed point?
Or perhaps ME would distribute source of the old version?
FloatToString changed...
Re: FloatToString changed...
Ok,OT wrote:I assume it is an intentional undocumented change and not a bug: FloatToString now outputs string in exponential format for numbers with an absolute value less than 1.0. (like 2.342536 e-1) instead of the fixed decimal places in the previous version. This really broke my LCD output routines which I designed to truncate part of the decimals to fit to the limited space on the LCD.
Also, because of this truncation I use, it was not easy to figure out what was going on firmware/hardware vise, since the exponential was not displayed in the output....
I do think the compilers are getting to the stage of maturity where one need to consider stability of code in the sense that new versions do not break old code because things like procedure calls and results are changed back and forth. For instance, if I had been a company maintaining a portfolio of instruments with different firmware, it would be very bothersome if code for all the instruments had to be changed with every new compiler version.
That said, would it be possible to get the old FloatToString back ,
or could we get two versions of the procedure, one with exponential and one which always use fixed point?
Or perhaps ME would distribute source of the old version?
We have missed to enter this change in help file, sorry about that. Also, we'll see about adding the old one in the library too.
I can send you the library, but I'll see what I can do about the source file.OT wrote:That would be nice. In the mean time, is it possible that you could send me the source of the old procedure, so that I do not have to revert back to the previous version of the compiler. zristic has my email address.
Thanks, I received the procedure and it compiles and runs. However in most cases it does not display the negative sign of negative numbers, and for small negative numbers it displays a negative sign at an improper place. I thought that the first problem had been fixed in ver. 4, and perhaps even before that, but may be not, I still had the workaround for this in my code. The second one seems perhaps to be a new one I have not detected before.
So may be there was a reason for the rewrite, and it is better to use the 5.0 version which is working properly (except for some rounding errors) as a starting point and extract the info needed for fixed decimal points from there...
So may be there was a reason for the rewrite, and it is better to use the 5.0 version which is working properly (except for some rounding errors) as a starting point and extract the info needed for fixed decimal points from there...
Hi,OT wrote:Thanks, I received the procedure and it compiles and runs. However in most cases it does not display the negative sign of negative numbers, and for small negative numbers it displays a negative sign at an improper place. I thought that the first problem had been fixed in ver. 4, and perhaps even before that, but may be not, I still had the workaround for this in my code. The second one seems perhaps to be a new one I have not detected before.
So may be there was a reason for the rewrite, and it is better to use the 5.0 version which is working properly (except for some rounding errors) as a starting point and extract the info needed for fixed decimal points from there...
Can you give me an example with this issue.
I discovered that my real code did not have the fix for the problem any longer anyway, so it indicated that ver. 4.03 actually did not have these problems. Are you sure that you sent me the 4.03 version of this procedure?
The test is pretty vanilla, and a small increment from a negative value demonstrated the problem clearly. It does show minus sign below -1.0, then no minus sign to -0.1, and then a misplaced minus sign, even more misplaced from -0,01. I also included output of the 5.0 version of FloatTo Str.
The unit called is the one you sent me, I just renamed the procedure to FloatToStrF and the Unit to FloatToStrFDP. The unit resided in the same folder as the program:
The test is pretty vanilla, and a small increment from a negative value demonstrated the problem clearly. It does show minus sign below -1.0, then no minus sign to -0.1, and then a misplaced minus sign, even more misplaced from -0,01. I also included output of the 5.0 version of FloatTo Str.
The unit called is the one you sent me, I just renamed the procedure to FloatToStrF and the Unit to FloatToStrFDP. The unit resided in the same folder as the program:
Code: Select all
program FloatToStrFixedTest;
USES FloatToStrFDP;
var
txt: string[23];
Rval : Real;
begin
ADPCFG := $F0FF; // PORTB is partly digital, pin 8-11 analog
TrisB := $0F0F;
LATB := $0000;
TRISC := $0000;
LATC := $0000; // Set all pins to zero;
TRISD := $0000; // configure pins of portd as output
LATD := $0000;
TRISF := $0000; // configure pins of portd as output
LATF := $0000;
Delay_ms(400);
Lcd_Init(PORTB, 7, 6, 5, 4, PORTD, 0, 1, 2);
//Dataport,pins, COntrPort,rs,rw,enable
Delay_ms(2000);
Rval:= -1.20;
While True do begin
Lcd_Cmd(LCD_CLEAR);
FloatToStrF(Rval,txt);
Lcd_Out(1, 1, txt);
FloatToStr(Rval,txt);
Lcd_Out(1, 2, txt);
Delay_ms(100);
Rval:= Rval+0.01;
end;
end.
Hi,OT wrote:I discovered that my real code did not have the fix for the problem any longer anyway, so it indicated that ver. 4.03 actually did not have these problems. Are you sure that you sent me the 4.03 version of this procedure?
The test is pretty vanilla, and a small increment from a negative value demonstrated the problem clearly. It does show minus sign below -1.0, then no minus sign to -0.1, and then a misplaced minus sign, even more misplaced from -0,01. I also included output of the 5.0 version of FloatTo Str.
The unit called is the one you sent me, I just renamed the procedure to FloatToStrF and the Unit to FloatToStrFDP. The unit resided in the same folder as the program:
Code: Select all
program FloatToStrFixedTest; USES FloatToStrFDP; var txt: string[23]; Rval : Real; begin ADPCFG := $F0FF; // PORTB is partly digital, pin 8-11 analog TrisB := $0F0F; LATB := $0000; TRISC := $0000; LATC := $0000; // Set all pins to zero; TRISD := $0000; // configure pins of portd as output LATD := $0000; TRISF := $0000; // configure pins of portd as output LATF := $0000; Delay_ms(400); Lcd_Init(PORTB, 7, 6, 5, 4, PORTD, 0, 1, 2); //Dataport,pins, COntrPort,rs,rw,enable Delay_ms(2000); Rval:= -1.20; While True do begin Lcd_Cmd(LCD_CLEAR); FloatToStrF(Rval,txt); Lcd_Out(1, 1, txt); FloatToStr(Rval,txt); Lcd_Out(1, 2, txt); Delay_ms(100); Rval:= Rval+0.01; end; end.
I have confirmed reported bugs in old version of FloatToStr function and sent corrected file to your email.
Thanks.
Srdjan, is it possible for you to email me the same floattostr library, as v.6 of the compiler only has exponent display format, and I need the original non-exponential display version - at least for now...thanks.srdjan wrote: Hi,
I have confirmed reported bugs in old version of FloatToStr function and sent corrected file to your email.
Thanks.
I am re-asking for the non exponent floattostr conversion library as I am debugging code using asin/acos math functions that return results in radians - the lcd output in exponent format is not helping at all.FRM wrote:Srdjan, is it possible for you to email me the same floattostr library, as v.6 of the compiler only has exponent display format, and I need the original non-exponential display version - at least for now...thanks.srdjan wrote: Hi,
I have confirmed reported bugs in old version of FloatToStr function and sent corrected file to your email.
Thanks.
Is there any chance of this?
Thankyou.
Hi,
Sorry for a late reply, somehow we have managed to miss this post of yours.
On the other hand, I have managed to misplace the library you have requested when changing my computer, so now I would have to search my backups in order to find it.
However, I think it would be easier for me to contact OT and ask him for the library file I have sent him
So, i think that there will be any problem for you to acquire this file. Just a little patience on your side.
Sorry for a late reply, somehow we have managed to miss this post of yours.
On the other hand, I have managed to misplace the library you have requested when changing my computer, so now I would have to search my backups in order to find it.
However, I think it would be easier for me to contact OT and ask him for the library file I have sent him
So, i think that there will be any problem for you to acquire this file. Just a little patience on your side.
No problem, thanks for the reply.srdjan wrote:Hi,
Sorry for a late reply, somehow we have managed to miss this post of yours.
On the other hand, I have managed to misplace the library you have requested when changing my computer, so now I would have to search my backups in order to find it.
However, I think it would be easier for me to contact OT and ask him for the library file I have sent him
So, i think that there will be any problem for you to acquire this file. Just a little patience on your side.
OT kindly did send me some code:
Code: Select all
{*******************************************************************************
Routine : FloatToStrFixed
Description : Convert 32-bit, signed single precision floating point number to
string
Parameters : <input> Single precision floating point number to be converted
<output> Output variable which will accept the resulting string
Notes : The result is given in format xxxxxxxxxxx.yyyyy, left justified
********************************************************************************}
procedure FloatToStrFixed(input: real; var output: array[23] of char);
var
tmpli: longint;
tmpr : real;volatile;
i, j : byte;
ch : byte;
pref,
suff : array[11] of char;
begin
tmpli := input;
LongintToStr(tmpli, pref);
if (tmpli = 0) and (input < 0) then // special case
pref[9] := '-';
tmpr := tmpli;
tmpr := input - tmpr;
tmpr := tmpr * 1.e+5; // take last five significant digits
tmpli := fabs(tmpr);
LongintToStr(tmpli, suff);
i := 0;
j := 0;
ch := pref[0];
while ch = 32 do
begin
inc(j);
ch := pref[j];
end;
while ch <> 0 do
begin
output[i] := ch;
inc(j);
inc(i);
ch := pref[j];
end;
output[i] := '.';
inc(i);
j := 6;
ch := suff[6];
while ch <> 0 do
begin
if ch = 32 then
ch := 48;
output[i] := ch;
inc(j);
inc(i);
ch := suff[j];
end;
output[i] := 0;
end;
Are you referring to another library routine?
Thanks.
- Well, that's exactly the reason we have introduced the new version of float to string library. Smaller and faster code.FRM wrote: At the moment in debugging is ok. Unfortunately using LongintToStr this routine takes 8k+ cycles whereas the Floattostr exponent version only consumes 2k+ cycles, which won't be ideal once this debugging session is over.
FRM wrote: Are you referring to another library routine?
- Noup. That's it.