Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
if comparison perform differently between Lite-c, C-Script. #270812
06/10/09 07:12
06/10/09 07:12
Joined: Oct 2003
Posts: 130
Wollongong Australia
J
Jethro Offline OP
Member
Jethro  Offline OP
Member
J

Joined: Oct 2003
Posts: 130
Wollongong Australia
Just spent 4 weeks converting my 75,000 lines of C-script code base to Lite-c. and discovered the following, among many other things.

var This_Var;

This_Var=0.1;
if (This_Var==0.1){beep();}

The above works in C-script but not in Lite-C

vars are supposed to have an accuracy of 0.001, so why doesn't the above work in Lite-c.
To get it to work you need to make This_Var a float, to up the resolution of the comparison.
or do the comparison like this.
if (This_Var==floatv(0.1)) {beep();}

Is this a bug or a quirk with Lite-c var comparisons, having a much lower resolution than specified.
I put var This_Var in a panel digit and it does indeed keep its value of 0.100 so it does seem to be the comparison at fault.

Jethro.

Re: if comparison perform differently between Lite-c, C-Script. [Re: Jethro] #270860
06/10/09 10:37
06/10/09 10:37
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
I think this is related to comparing float numbers with "==".

In programming course I learnt that due to limited computer precision, float numbers can not be compared with == or !=, but always with <, <=, >, >=.

This_Var=0.1;
if (This_Var > 0.0999) printf("Match!");
if (This_Var < 0.1001) printf("Match!");

Re: if comparison perform differently between Lite-c, C-Script. [Re: Tobias] #270864
06/10/09 10:44
06/10/09 10:44
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
Quote:
so why doesn't the above work in Lite-c.


because in lite-c the literals are doubles not vars like in c-script.

Re: if comparison perform differently between Lite-c, C-Script. [Re: ventilator] #270872
06/10/09 11:03
06/10/09 11:03
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
This would also work:

This_Var=0.1;
That_Var=0.1;

if (This_Var == That_Var) printf("Match!");

Still if a variable is not an integer, you should not compare it with ==.

Re: if comparison perform differently between Lite-c, C-Script. [Re: Tobias] #270915
06/10/09 14:05
06/10/09 14:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I think ventilator is right.
A regular workaround I use is
if(This_Var==(var)0.1) beep();


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: if comparison perform differently between Lite-c, C-Script. [Re: EvilSOB] #271051
06/11/09 03:07
06/11/09 03:07
Joined: Oct 2003
Posts: 130
Wollongong Australia
J
Jethro Offline OP
Member
Jethro  Offline OP
Member
J

Joined: Oct 2003
Posts: 130
Wollongong Australia
Thanks guys for all your responses.
ventilators makes perfect sense, to what I was thinking must be the culprit.

I'll have to be more carefull now with lite-c.

Jethro.

Re: if comparison perform differently between Lite-c, C-Script. [Re: Jethro] #271082
06/11/09 07:26
06/11/09 07:26
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
We'll mention this in the manual.


Moderated by  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1