Hacker News new | past | comments | ask | show | jobs | submit login

Unless you have a floating point model that supports arbitrary bases, you're always going to have the issue. Binary floats are unable to represent 1/10 just as decimal floats are unable to represent 1/3.

And in case anyone's wondering about handling it by representing the repeating digits instead, here's the decimal representation of 1/12345 using repeating digits:

  0.0[0008100445524503847711624139327663021466180639935196435803969218307006885378
  69582827055488051842851356824625354394491697043337383556095585257189145402997164
  84406642365330093155123531794248683677602268124746861077359254759011745646010530
  57918185500202511138112596192790603483191575536654515998379910895099230457675172
  13446739570676387201296071283920615633859862292426083434588902389631429728635074
  92912110166059133252328878088294856217091940056703118671526933981368975293641150
  26326447954637505062778452814904819765087079789388416362899959497772377480761441
  87930336168489266909680032401782098015390846496557310652085864722559740785743215
  87687322802754151478331308221952207371405427298501417577966788173349534224382341
  02875658161198865937626569461320372620494127176994734710409072498987444309437019
  03604698258404212231672742]



Nice example. For those who do not understand why it is so long, a denominator multiplied by a period must be all-nines. E.g. 1/7 = 0.(142857), because 142857x7 = 999999, so that 0.(142857)x7 = 0.(999999) = 1 back again. For some simple numbers N their nearest 999...999/N integer counterpart is enormously huge.


> Unless you have a floating point model that supports arbitrary bases

See also binary coded decimals.

https://en.wikipedia.org/wiki/Binary-coded_decimal


That's not a floating point.


From the article:

> Programmable calculators manufactured by Texas Instruments, Hewlett-Packard, and others typically employ a floating-point BCD format, typically with two or three digits for the (decimal) exponent.


Then that's how they're encoding the components of the float. BCD itself is not a floating-point, it's just a different way of encoding a fixed-point or integer. If all you want to do is use floating point but expand the logarithm and mantissa then that's completely tangential to whether or not they're stored as BCD or regular binary values.


> Binary floats are unable to represent 1/10 just as decimal floats are unable to represent 1/3.

That is true, but most humans in this world expect 0.1 to be represented exactly but would not require 1/3 to be represented exactly. Because they are used to the quirks of the decimal point (and not of the binary point).

This is a social problem, not a technical one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: