FloatToString changed...

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

FloatToString changed...

#1 Post by OT » 06 Mar 2007 06:50

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 :lol: ,
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?

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: FloatToString changed...

#2 Post by srdjan » 06 Mar 2007 08:29

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 :lol: ,
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?
Ok,
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.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#3 Post by OT » 08 Mar 2007 05:47

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.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#4 Post by srdjan » 08 Mar 2007 09:08

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.
I can send you the library, but I'll see what I can do about the source file.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#5 Post by OT » 08 Mar 2007 21:06

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...

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#6 Post by srdjan » 09 Mar 2007 08:37

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...
Hi,
Can you give me an example with this issue.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#7 Post by OT » 10 Mar 2007 09:02

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.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#8 Post by srdjan » 12 Mar 2007 17:09

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.
Hi,
I have confirmed reported bugs in old version of FloatToStr function and sent corrected file to your email.
Thanks.

OT
Posts: 581
Joined: 19 May 2005 05:08
Location: Fairbanks, Alaska

#9 Post by OT » 13 Mar 2007 14:06

Thanks so much for resolving this so quickly. It tested very well on my board. Now with the corrected version, it seems tempting to include it as the second version in the library.

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#10 Post by FRM » 01 Nov 2007 10:01

srdjan wrote: Hi,
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.

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#11 Post by FRM » 07 Nov 2007 16:46

FRM wrote:
srdjan wrote: Hi,
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.
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.

Is there any chance of this?

Thankyou.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#12 Post by srdjan » 08 Nov 2007 13:36

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 :wink:
So, i think that there will be any problem for you to acquire this file. Just a little patience on your side. :)

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#13 Post by FRM » 08 Nov 2007 15:05

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 :wink:
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.

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;
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. :(

Are you referring to another library routine?

Thanks.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#14 Post by srdjan » 08 Nov 2007 15:52

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. :(
- Well, that's exactly the reason we have introduced the new version of float to string library. Smaller and faster code. :D
FRM wrote: Are you referring to another library routine?


- Noup. That's it.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”