Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, Ayumi, VHX, monarch), 1,161 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
double trouble with numbers #160682
10/12/07 16:49
10/12/07 16:49
Joined: Dec 2005
Posts: 22
A
Attila Offline OP
Newbie
Attila  Offline OP
Newbie
A

Joined: Dec 2005
Posts: 22
I try to get numbers like 0.0001, -0.0004 from a text file.
This is my lite-C Pure code of an action.
I get an ugly error window saying that acknex.exe has to be closed.
Is there something wrong of how i declare a double variable?

action in_node_000()
{

STRING reader;
double check;
var filehandle;

filehandle = file_open_read("mytextfile");

if (filehandle > 0){
file_str_read(filehandle,reader);

file_close(filehandle);

check = str_to_num(reader);

while(check == 0.00001){

my.pan += 1;
wait(1);

}
}

}

Re: double trouble with numbers [Re: Attila] #160683
10/12/07 21:34
10/12/07 21:34
Joined: Oct 2006
Posts: 106
i_program_games Offline
Member
i_program_games  Offline
Member

Joined: Oct 2006
Posts: 106
Try
STRING* reader;
as opposed to STRING reader;


Chaos is a paradox consistently inconsistent.
Re: double trouble with numbers [Re: i_program_games] #160684
10/13/07 01:22
10/13/07 01:22
Joined: Dec 2005
Posts: 22
A
Attila Offline OP
Newbie
Attila  Offline OP
Newbie
A

Joined: Dec 2005
Posts: 22
I tried to debug, and I foung file_open_read returns NULL value.
I checked, I have the file in work folder and numbers in it like this

1
-2
3
4
3
-5

Still I cannot read them in pure c-lite mode.

Re: double trouble with numbers [Re: Attila] #160685
10/13/07 22:45
10/13/07 22:45
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
The numbers have to be on the same line (I think)
like
1 -2 3 4 3 -5

I use them on the same line and it works.

Re: double trouble with numbers [Re: Ottawa] #160686
10/16/07 23:44
10/16/07 23:44
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
Code:

double check;

...

while(check == 0.00001){
my.pan += 1;
wait(1);
}



This will probably not work. To check it, set "check = 0.00001;" and try the while loop.

I say probably because, depending on the compiler, it might work in this case. But it is always a bad idea to compare floating point values using "==" since the numbers are not always exact.


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: double trouble with numbers [Re: Doug] #205141
05/04/08 12:20
05/04/08 12:20
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
(Digging this up to add some useful information -- I saw the thread under "who's online")

Doug is right. Floating point numbers are mostly never equal a specific value except you set them onto it. Better use a function, that calculates the difference and proves it against a threshold value.

Algorithm:
 Code:
bool fEqual (double f1, double f2) {
	static const double EPSILON = 0.001;
	return((bool)(fabs(f1-f2) <= EPSILON));
}


Last edited by HeelX; 05/04/08 12:21.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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