closed

Loginbox

Please enter your username and password into the following fields to log in.


  • Username:
  • Password:
  •  
  • Auto log in on every visit.


  •  

FloatToStr(f:n:n) problem



allan offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age: 57
Posts: 10
Registered: 10 / 2016
Private message
Subject: FloatToStr(f:n:n) problem  -  Posted: 04.10.2017 - 16:50   -  
Hi,
With new compiler (5.09.18) any attempt to convert float to string causes crash!
This does not work any more, even in simulator:

Float1 := 0.1001;
Float2 := 2.0002;
st := FloatToStr(Float1:6:4) + ' ' + FloatToStr(Float2:6:4);
go down go up
Gunter online
Administrator
Avatar
Gender: male
Location: GERMANY  Frankfurt Main / Germany
Age:
Posts: 1530
Registered: 02 / 2003
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 04.10.2017 - 23:20   -  
2 Dinge sind unendlich: das Universum und die menschliche Dummheit.
Aber bei dem Universum bin ich mir noch nicht ganz sicher
--
Albert Einstein

---
The concept of global warming was created by and for the Chinese in order to make U.S. manufacturing non-competitive
--
Donald J. Trump on Twitter
go down go up
allan offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age: 57
Posts: 10
Registered: 10 / 2016
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 13:04   -  
OK, understood, but this is so easy to reproduce, just copy-paste these 3 lines and try.
Something bad happened to floating point numbers while I did not update (since 2012).

Code

program avrprommer;

{$NOSHADOW}

{ $W+ Warnings}            {Warnings off}

Device = mega64, VCC=3.3;

Import SysTick, WatchDog;

From System Import  Float;

Define
        ProcClock   = 6000000;

        SysTick     = 10;            {msec}
        StackSize   = $0040, iData;
        FrameSize   = $0040, iData;
        
        WatchDog       = msec2000;



Implementation


{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }

type

{--------------------------------------------------------------}
{ Const Declarations }


{$EEPROM}
{--------------------------------------------------------------}

Structconst



{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}

Var

        st             : string[16];
        Float1, Float2 : float;

const


{--------------------------------------------------------------}
{ functions }




{ Main Program }
{$IDATA}

begin

  // ----- DEBUG  ----
  Float1 := 0.1001;
  Float2 := 2.0002;
  st := FloatToStr(Float1:6:4)  + '  ' + FloatToStr(Float2:6:4);

  
end avrprommer.

go down go up
Gunter online
Administrator
Avatar
Gender: male
Location: GERMANY  Frankfurt Main / Germany
Age:
Posts: 1530
Registered: 02 / 2003
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 14:33   -  
Hi.

I found no problem with 5.09.18

Gunter
You must be logged in or your permissions are to low to see this Attachment(s).
2 Dinge sind unendlich: das Universum und die menschliche Dummheit.
Aber bei dem Universum bin ich mir noch nicht ganz sicher
--
Albert Einstein

---
The concept of global warming was created by and for the Chinese in order to make U.S. manufacturing non-competitive
--
Donald J. Trump on Twitter
go down go up
rh offline
Administrator
Avatar
Gender: male
Location: GERMANY  Germany
Age:
Posts: 5133
Registered: 03 / 2002
Homepage Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 15:18   -  
Allan, Gunter,

I also checked this example

rolf
You must be logged in or your permissions are to low to see this Attachment(s).
Cars don't buy cars -- Autos kaufen keine Autos.
Henry Ford
go down go up
allan offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age: 57
Posts: 10
Registered: 10 / 2016
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 17:37   -  
I see - if you just 'Make' it works, but 'Make & Optimize' was what I did...
So it must be optimizer related problem.
go down go up
Gunter online
Administrator
Avatar
Gender: male
Location: GERMANY  Frankfurt Main / Germany
Age:
Posts: 1530
Registered: 02 / 2003
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 17:53   -  
yes you are right !
Optimize creates an endless loop.

Merlin ?

Edit:
the problem is the optimisation of the FloatToStr function !
even "st := FloatToStr (1);" creates a loop.
You must be logged in or your permissions are to low to see this Attachment(s).
2 Dinge sind unendlich: das Universum und die menschliche Dummheit.
Aber bei dem Universum bin ich mir noch nicht ganz sicher
--
Albert Einstein

---
The concept of global warming was created by and for the Chinese in order to make U.S. manufacturing non-competitive
--
Donald J. Trump on Twitter
This post has been edited 2-times. Last edit: 05.10.2017 - 18:25 by Gunter.
go down go up
rh offline
Administrator
Avatar
Gender: male
Location: GERMANY  Germany
Age:
Posts: 5133
Registered: 03 / 2002
Homepage Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 18:56   -  
Hello Allan,

without complete environment and other infos we can't
evaluate such problems.
As always:
doesn't work ... doesn't help

rolf
Cars don't buy cars -- Autos kaufen keine Autos.
Henry Ford
go down go up
Merlin offline
Schreiberling
Avatar
Gender: male
Location: UNITED KINGDOM 
Age:
Posts: 755
Registered: 03 / 2005
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 05.10.2017 - 21:21   -  
I will investigate.
Merlin.

:magic:

Software is a black art.
go down go up
Merlin offline
Schreiberling
Avatar
Gender: male
Location: UNITED KINGDOM 
Age:
Posts: 755
Registered: 03 / 2005
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 06.10.2017 - 10:00   -  
@Allan As a quick fix while I investigate further, if you add the following line near the top of your code it will disable the latest optimization while I investigate further

Code
{$OPTI NO_OPT_TST}
Merlin.

:magic:

Software is a black art.
go down go up
allan offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age: 57
Posts: 10
Registered: 10 / 2016
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 06.10.2017 - 11:34   -  
@Merlin, thanks!
It solves the actual problem I had with real project where comparing floating point numbers gave random results. This FloatToStr was only needed for debugging and also was easy to reproduce!
go down go up
Merlin offline
Schreiberling
Avatar
Gender: male
Location: UNITED KINGDOM 
Age:
Posts: 755
Registered: 03 / 2005
Private message
Subject: Re: FloatToStr(f:n:n) problem  -  Posted: 06.10.2017 - 13:30   -  
Hi Allan.

I have now fixed the bug. Either you can wait for next update or if you let me know your e-mail via pm I will send you the fix directly.
Merlin.

:magic:

Software is a black art.
go down go up
 


Registered users in this topic
Currently no registered users in this section

Delete cookies of this forum  •  FAQ / Help  •  Team page  •  Imprint   |  Local time: 13.12.2017 - 08:12