0

So this is more of a math question and due to memory limits in computers it makes no difference, but to my knowledge mathematically speaking 0,99..9 = 1 so when we say that 1 is excluded [0,1) what would the proper notation be for Math.random()*2 the lower limit is clear [0, 2), but shouldn't 0,99..8 * 2 be 1,99..6 thus exluding 1,99..7, 1,99..8 as possible answers. I guess my mistake is that I'm not understanding infinity properly and the answer is just simply [0,2), but it doesn't seem a trival answer.

Thanks in advance, Carlos

  • Computers straight up *cannot* represent infinitely recurring sequences of numbers. All you get is an approximate value that *hopefully* matches the value you think you have. See [Is floating point math broken?](https://stackoverflow.com/q/588004) for an intro on the topic. – VLAZ Oct 17 '20 at 09:41

1 Answers1

0

We can understand this concept as follows:

We can simply use one principle that any number in decimal can be divided by two.

now for 1.999999..(10 times)

it can also be divided by 2 which is 0.99,999,999,995 (commas for easy count)

which is again less than 1.

Divyessh
  • 2,540
  • 1
  • 7
  • 24