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/0721:3410/12/0721:34
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.
(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.