Why can't decimal numbers be represented exactly in binary?

前端 未结 20 3529
不知归路
不知归路 2020-11-21 05:15

There have been several questions posted to SO about floating-point representation. For example, the decimal number 0.1 doesn\'t have an exact binary representation, so it\'

20条回答
  •  故里飘歌
    2020-11-21 05:46

    In the equation

    2^x = y ;  
    x = log(y) / log(2)
    

    Hence, I was just wondering if we could have a logarithmic base system for binary like,

     2^1, 2^0, 2^(log(1/2) / log(2)), 2^(log(1/4) / log(2)), 2^(log(1/8) / log(2)),2^(log(1/16) / log(2)) ........
    

    That might be able to solve the problem, so if you wanted to write something like 32.41 in binary, that would be

    2^5 + 2^(log(0.4) / log(2)) + 2^(log(0.01) / log(2))
    

    Or

    2^5 + 2^(log(0.41) / log(2))
    

提交回复
热议问题