Instead of x != 1.0
put x < 1.0
. This, at least, will definitely end your loop.
A binary system, such as those that run all of our modern computers, cannot (easily) represent fractions, especially those that cannot be accurately represented in decimal form. This is where a weird number comes in when you should have .0003
. This is an artifact of how numbers are represented internally.
Some languages ββdo better with numbers and accuracy than others, so if the accuracy of numbers matters, you either need to use a different language or use a library that handles the number of things for you (meaningful numbers and all that), or you need to handle it independently with appropriate rounding, etc. at every step.
cdeszaq
source share