M mw71 Well-Known Member Licensed User Longtime User Oct 8, 2019 #1 Hi, 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.
Hi, 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.
E emexes Expert Licensed User Longtime User Oct 8, 2019 #2 mw71 said: with 1 no change. Click to expand... Is the number larger than ~16 million? Any chance of a peek at the code? Upvote 0
mw71 said: with 1 no change. Click to expand... Is the number larger than ~16 million? Any chance of a peek at the code?
M mw71 Well-Known Member Licensed User Longtime User Oct 8, 2019 #3 no, 27000000 with +/- 10 or 100 all o.k., but not with 1 Code like this: Code: Copy Dim X as Float 'and in the Sub, dependent on Encoder X=X+1 'or X=X-1 Upvote 0
no, 27000000 with +/- 10 or 100 all o.k., but not with 1 Code like this: Code: Copy Dim X as Float 'and in the Sub, dependent on Encoder X=X+1 'or X=X-1
E emexes Expert Licensed User Longtime User Oct 8, 2019 #4 emexes said: Is the number larger than ~16 million? Click to expand... mw71 said: no, 27000000 Click to expand... I'll interpret that as: yes, it is larger than 16 million Change the Float to a Double. Or a Long, if it is only ever whole numbers ie no fractional part. Upvote 0
emexes said: Is the number larger than ~16 million? Click to expand... mw71 said: no, 27000000 Click to expand... I'll interpret that as: yes, it is larger than 16 million Change the Float to a Double. Or a Long, if it is only ever whole numbers ie no fractional part.
maXim Active Member Licensed User Longtime User Oct 8, 2019 #5 Hi mw71, try with: Code: Copy x = x + 1.0 'or x = x - 1.0 Upvote 0
M mw71 Well-Known Member Licensed User Longtime User Oct 8, 2019 #6 emexes said: I'll interpret that as: yes, it is larger than 16 million Click to expand... , you rigth..... emexes said: Change the Float to a Double. Or a Long, if it is only ever whole numbers ie no fractional part. Click to expand... i have change to ULong (after check the dependencies), now it works maXim said: Hi mw71, try with: Code: Copy x = x + 1.0 'or x = x - 1.0 Click to expand... unfortunately that does not work (test in B4R direct an inline c...) Upvote 0
emexes said: I'll interpret that as: yes, it is larger than 16 million Click to expand... , you rigth..... emexes said: Change the Float to a Double. Or a Long, if it is only ever whole numbers ie no fractional part. Click to expand... i have change to ULong (after check the dependencies), now it works maXim said: Hi mw71, try with: Code: Copy x = x + 1.0 'or x = x - 1.0 Click to expand... unfortunately that does not work (test in B4R direct an inline c...)
E emexes Expert Licensed User Longtime User Oct 8, 2019 #7 mw71 said: now it works Click to expand... Super! 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: Oct 8, 2019 Upvote 0
mw71 said: now it works Click to expand... Super! 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?).