B4R Question Incrase/Decrase Float by 1


Active Member
Licensed User

is there a way to incrase or decrase a float by 1?
Inc/Dec by 10, 100, all o.k., but with 1 no change.


Active Member
Licensed User
no, 27000000
with +/- 10 or 100 all o.k., but not with 1

Code like this:
Dim X as Float

'and in the Sub, dependent on Encoder
X=X+1 'or X=X-1


Active Member
Licensed User
I'll interpret that as: yes, it is larger than 16 million
:oops:, you rigth.....

Change the Float to a Double. Or a Long, if it is only ever whole numbers ie no fractional part.
i have change to ULong (after check the dependencies), now it works

Hi mw71,

try with:

x = x + 1.0  'or x = x - 1.0
unfortunately that does not work (test in B4R direct an inline c...)


Well-Known Member
Licensed User
now it works

The reason was probably: a Float (single precision) is 1 32-bit type. 8 bits are used for the exponent, 1 for the sign, and 23 bits for the mantissa (the actual number part).

There is a bonus mantissa bit because we know it does not begin with a "0" (similar to the way that, when you write a number, you don't write leading zeroes).

24 bits can represent numbers up to 2^24 = 16-and-a-bit million. Once you go higher, to numbers that need 25 bits, the lower bit is "lost" and consequently the Float number can now only represent numbers where that lost bit is zero, ie even numbers / every second number.

A 32-bit ULong can hold numbers up to (one less than) 2^32, so that'll get you to just over 4 billion (4 GHz?).
Last edited: