v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

#1 Post by Dany » 06 Dec 2010 13:46

Hi, the "FloatToStr" routine (Conversions lib) in v4.15 does not behave as in the help example:

Code: Select all

  
var ff1, ff2, ff3 : real;
    txt : array[23] of char;
  ...
  ff1 := -374.2;
  ff2 := 123.456789;
  ff3 := 0.000001234;

  FloatToStr(ff1, txt);  // txt is "-374.2"    // actually '-374.20001'
  FloatToStr(ff2, txt);  // txt is "123.4567"  // actually '123.45678'
  FloatToStr(ff3, txt);  // txt is "1.234e-6"  // actually '0.00000' (still so in v4.60)'
As you can see, especially the last one is odd, I did expect the "...e..." notation here.

Also, the longest string (txt) needed was of length 10, why is it specified as 23?
Last edited by Dany on 06 Jan 2011 21:22, edited 3 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: v4.15: Odd "FloatToStr" behaviour?

#2 Post by filip » 09 Dec 2010 16:08

Hi,

It will be fixed.
Thank you for reporting this.

Regards,
Filip.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: v4.15: Odd "FloatToStr" behaviour?

#3 Post by Dany » 06 Jan 2011 21:22

filip wrote:Hi,

It will be fixed.
Thank you for reporting this.

Regards,
Filip.
Solved in v4.60. The help file is adapted to reflect the actual behaviour of "FloatToStr" .
Thanks mE! :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

frasca
Posts: 21
Joined: 02 Feb 2011 10:32

Re: v4.15: Odd "FloatToStr" behaviour?

#4 Post by frasca » 07 Apr 2011 15:48

Dany wrote:
filip wrote:Hi,

It will be fixed.
Thank you for reporting this.

Regards,
Filip.
Solved in v4.60. The help file is adapted to reflect the actual behaviour of "FloatToStr" .
Thanks mE! :D :D
is a solution to change the help file???
or is better to remove the bug?

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

#5 Post by janni » 07 Apr 2011 15:55

It wasn't a bug. It was description from mC left in mP help file.

frasca
Posts: 21
Joined: 02 Feb 2011 10:32

Re: v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

#6 Post by frasca » 07 Apr 2011 21:05

janni wrote:It wasn't a bug. It was description from mC left in mP help file.

Code: Select all

FloatToStr(ff3, txt);  // txt is "1.234e-6"  // actually '0.00000' (still so in v4.60)'
This is my problem... the old version when the number is too small it becomes exponential notation!!! Good idea!! the new version return 0.00000 that is wrong!!

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

#7 Post by janni » 07 Apr 2011 22:50

I see what you mean, though there are some that would not like seeing engineering notation on their LCD just because calculation result is a little off zero due to rounding problems. Either implementation of FloatToStr may be inconvenient for some applications.
Maybe a request for two versions of FloatToStr in Wish List forum would be in place?
...the old version when the number is too small it becomes exponential notation!!!
I cannot recall - which version of mikroPascal had FloatToStr working this way?

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: v4.15: Odd "FloatToStr" behaviour (solved in v4.60)

#8 Post by tihomir.losic » 08 Apr 2011 07:14

janni wrote:It wasn't a bug. It was description from mC left in mP help file.
Hello Janni,

I agree with you.
Given floating point number will be truncated to 7 most significant digits before conversion.
For example:

Code: Select all

float ff1 = -374.2;
float ff2 = 123.456789;
float ff3 = 0.000001234;
char txt[15];
...
FloatToStr(ff1, txt);  // txt is "-374.2"
FloatToStr(ff2, txt);  // txt is "123.4567"
FloatToStr(ff3, txt);  // txt is "1.234e-6"
Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”