Home   Help Search Login Register  

Author Topic: Range of number variables (Integer?)  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

Offline Haretuerk

  • Members
  • *
    • Kanonenfutter.org
Range of number variables (Integer?)
« on: 02 Mar 2009, 16:00:05 »
Hi Folks,

what's the range of normal number variables? -32000 to +32000? -65000 to +65000?

I was looking here, but didn't find anything about the range.... http://community.bistudio.com/wiki/Number

Thanks!

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Range of number variables (Integer?)
« Reply #1 on: 02 Mar 2009, 21:20:48 »
I don't know the exact limit but it's much higher than 2^16 (65536). The engine most probably uses floating point numbers internally (single precision?) so you better avoid numbers with more than 7 digits.

Code: [Select]
_n1 = 2^32;
_n2 = 2^32 - 1;
hint str(_n1 == _n2); // -> TRUE


Note: I did my tests in ArmA not OFP.
try { return true; } finally { return false; }

Offline Ext3rmin4tor

  • Members
  • *
Re: Range of number variables (Integer?)
« Reply #2 on: 07 Mar 2009, 15:33:11 »
I think they use double precision, in any case there is no distinction between integer and real numbers (in fact there is only a Number type variable, not integer type, float type and double type like in any common programming language), so the boundary is the same for both. Besides remember that one bit is used to code the sign, so the maximum magnitude (that is the value without the sign) is 2^31 for single precision and 2^63 for double precision. In any case do you really need a number greater than 2^32  :D ??
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Range of number variables (Integer?)
« Reply #3 on: 08 Mar 2009, 19:22:09 »
The ranges you specify are misleading. Floating point numbers don't work like integers. And I'm pretty sure they use single precision:

  hint str(3.402823 * 10^38) // -> 3.40282e+038
  hint str(3.402824 * 10^38) // -> 1.#INF (exceeds max. float)


I think the correct answer is:

The numbers we deal with in OFP/ArmA are single precision floating point numbers that have at least 6 significant digits and a magnitude between about 10^-38 and 10^38.

Keep in mind that floating point numbers have a limited precision, i.e. some numbers are rounded, which leads to funny results:

Code: [Select]
hint str( sqrt(2)^2 );        // -> 2
hint str( sqrt(2)^2 == 2 );   // -> FALSE
hint str( 2^24 == 2^24 + 1 ); // -> TRUE
try { return true; } finally { return false; }