#### Lord KJWilliams

##### Member

To quote what someone told me ( see the link to see what my original post is - note its uses C terminology) , this is a truncated copy :

actually the value I meant was 1(10e-3) which means 10**-3 ( note : " ** " means raise to the power of ) - but whatever....Barry Schwarz

9/24/12

Most simple decimal fractions cannot be expressed exactly in the

floating point representation used by most computers. In the

mathematical world, 23.0010 - 23 will always equal 0.0010 exactly. In

the world of computers, as exemplified by my system, the difference is

0..0010000000000012. Needless to say, this won't compare equal to

0.0010.

Since comparing for exact equality is not productive, there are a

couple of options:

If you are only interested in a fixed number of decimal places

(such as four as implied by your example), you could multiply all the

values by the appropriate power of 10 (10,000 for four), and use only

the integer portion of the products. So instead of comparing y to

0.0010 you would compare (int)(y*10000) to 10.

The more general solution is to check, not for equality, but for

"closeness". Instead of y==0.0010, try abs(y-0.0010)<1e-9. That

epsilon value (1e-9 in this case) actually needs to be scaled based on

the magnitude of the comparands. If you were comparing numbers in the

range of c (the speed of light in cm/sec), you might use an epsilon of

1e3 instead. The scaling is also affected by the number of

significant digits in your values which in turn is also impacted by

your C compiler and run-time library.

....

....

Scientific notation, and every other form of visible representation

such as decimal, binary, hexadecimal, octal, etc, apply only to how

people see and enter values. It has nothing to do with how the value

is stored or manipulated in the computer. All floating point values

are rounded to (technically approximated by) the closest value that

can be stored exactly. 1e-3 and 0.0010 are the exact same value as

far as your system is concerned. And neither is stored in the

computer as exactly that value. (I assume your 10e-3 was just a "slip

of the tongue".) So yes, y==1e-3 would evaluate to false exactly for

the same reason that y==0.0010 does.

Would I have the same problem in GML for evaluating exact values that are floating point values, as I did in C programming, as the guy stated in the response ? Would I have to resort to the same tactics in used C programming, but instead in GML programming - for evaluation of floating point values ? Is he correct in his response?

Thanks in Advance