Blueforcer Well-Known Member Licensed User Longtime User Jun 5, 2020 #1 Hey, I increase a double by 0.1, 0.2 or 0.5 (depending on the setting) with every tick. now i want to detect when the double value is an interger e.g 1,2,3,4,5,6 and so on. how can i do this? thanks in advise Last edited: Jun 5, 2020
Hey, I increase a double by 0.1, 0.2 or 0.5 (depending on the setting) with every tick. now i want to detect when the double value is an interger e.g 1,2,3,4,5,6 and so on. how can i do this? thanks in advise
agraham Expert Licensed User Longtime User Jun 5, 2020 #2 It is not advisable to try to do integer checks on Doubles that have been incremented by fractional decimal multiplication as Doubles, being a finite length binary representation of a number, cannot accurately represent decimal fractions so for example (n*10)/n may not result in the naively expected integer value, 10, but may result in something like 10.0000001 or 9.99999. Repeated operations may compound the effect. This is common to all binary computer architectures. For simplicity I would recommend using Ints or Longs and scaling the multiplier values appropriately. Upvote 0
It is not advisable to try to do integer checks on Doubles that have been incremented by fractional decimal multiplication as Doubles, being a finite length binary representation of a number, cannot accurately represent decimal fractions so for example (n*10)/n may not result in the naively expected integer value, 10, but may result in something like 10.0000001 or 9.99999. Repeated operations may compound the effect. This is common to all binary computer architectures. For simplicity I would recommend using Ints or Longs and scaling the multiplier values appropriately.
Blueforcer Well-Known Member Licensed User Longtime User Jun 5, 2020 #3 ok thanks! Now i changed everything to integer. So i increasing by 1 and check via modulo whether it is divisible by x. Thats working And yes i checked the addition of the doubles and it is as you said Upvote 0
ok thanks! Now i changed everything to integer. So i increasing by 1 and check via modulo whether it is divisible by x. Thats working And yes i checked the addition of the doubles and it is as you said
Harris Expert Licensed User Longtime User Jun 6, 2020 #4 Except for short loop incrementers, I avoid using Int... I use a Long, since we are blessed with much more system memory... This is especially true when one uses a datetime to store as a var declared as int.... Just a hint, I have been bitten too often, spent too much time degugging - now I know better and understand why... Upvote 0
Except for short loop incrementers, I avoid using Int... I use a Long, since we are blessed with much more system memory... This is especially true when one uses a datetime to store as a var declared as int.... Just a hint, I have been bitten too often, spent too much time degugging - now I know better and understand why...
Blueforcer Well-Known Member Licensed User Longtime User Jun 6, 2020 #5 I just increase up to 1000 than reset. Upvote 0