Hello everybody.
I've created my own particular version of the Java FX program for the Bouncing Ball.
I was testing the method decreaseSpeed() in order to try to understand the variation of the decrease of the rateProperty of the Timeline Animation.
The increase of the speed is done using the UP key in the Keyboard.
The decrease of the speed is done using the DOWN key in the Keyboard.
The first thing I've discovered is that the Increase/Decrease of the rateProperty of the Timeline Animation is not uniform.
For example a uniform increase/decrease (using only integers as simplification would be)
1 -> 2 -> 3 -> 4
4 -> 3 -> 2 -> 1
In this example every time I would increase I would increase it by adding one.
If I was decreasing I would decrease it by subtracting one.
In my program the rate is a double but is not uniform.
In my first run decrease I get:
The current rate is 1.100000000000001
The current rate is 1.0000000000000009
The current rate is 0.9000000000000009
The current rate is 0.8000000000000009
The current rate is 0.700000000000001
The current rate is 0.600000000000001
The current rate is 0.500000000000001
The current rate is 0.400000000000001
The current rate is 0.30000000000000104
The current rate is 0.20000000000000104
The current rate is 0.10000000000000103
Then I increased the rate a little, and after that I decreased it again, and I got this:
The current rate is 1.0999999999999999
The current rate is 0.9999999999999999
The current rate is 0.8999999999999999
The current rate is 0.7999999999999999
The current rate is 0.7
The current rate is 0.6
The current rate is 0.5
The current rate is 0.4
The current rate is 0.30000000000000004
The current rate is 0.20000000000000004
The current rate is 0.10000000000000003
As you can see the values are different in the two times.
But that is not why I'm making this post.
When I decrease the rate the Rate reaches 0 and if, after that, I try to decrease it again it stays 0.
But, before the rateProperty gets to Zero, I always get a Negative number before it.
So, in the next lines, there are two examples, and in both Examples I get a Negative rate Property.
I've Increased the Rate Property before this
The current rate is 2.8000000000000016
The current rate is 2.7000000000000015
The current rate is 2.6000000000000014
The current rate is 2.5000000000000013
The current rate is 2.4000000000000012
The current rate is 2.300000000000001
The current rate is 2.200000000000001
The current rate is 2.100000000000001
The current rate is 2.000000000000001
The current rate is 1.9000000000000008
The current rate is 1.8000000000000007
The current rate is 1.7000000000000006
The current rate is 1.6000000000000005
The current rate is 1.5000000000000004
The current rate is 1.4000000000000004
The current rate is 1.3000000000000003
The current rate is 1.2000000000000002
The current rate is 1.1
The current rate is 1.0
The current rate is 0.9
The current rate is 0.8
The current rate is 0.7000000000000001
The current rate is 0.6000000000000001
The current rate is 0.5000000000000001
The current rate is 0.40000000000000013
The current rate is 0.30000000000000016
The current rate is 0.20000000000000015
The current rate is 0.10000000000000014
The current rate is 1.3877787807814457E-16
This is a negative current rate
The current rate is -0.09999999999999987
The current rate is 0.0
The current rate is 0.0
The current rate is 0.0
I've Increased the Rate Property before this
The current rate is 2.3000000000000007
The current rate is 2.2000000000000006
The current rate is 2.1000000000000005
The current rate is 2.0000000000000004
The current rate is 1.9000000000000004
The current rate is 1.8000000000000003
The current rate is 1.7000000000000002
The current rate is 1.6
The current rate is 1.5
The current rate is 1.4
The current rate is 1.2999999999999998
The current rate is 1.1999999999999997
The current rate is 1.0999999999999996
The current rate is 0.9999999999999997
The current rate is 0.8999999999999997
The current rate is 0.7999999999999997
The current rate is 0.6999999999999997
The current rate is 0.5999999999999998
The current rate is 0.4999999999999998
The current rate is 0.3999999999999998
The current rate is 0.2999999999999998
The current rate is 0.19999999999999982
The current rate is 0.09999999999999981
This is a negative current rate
The current rate is -1.942890293094024E-16
The current rate is 0.0
The current rate is 0.0
The current rate is 0.0
Can someone please explain me why this happens and if it is sort of an Overflow / Underflow ?
Thank you,
Rogério