Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • Possibly the first case I've encountered where image loaded before the text. A grid of 1px rectangles? How unsettling.
  • Besides Python’s fractions, there are also constructive reals, exemplified by Android calculator where you can swipe any answer to get as many digits as you want.
  • Great blog post by Peter Gibbons, Michael Bolton, and Samir "Nagana-work-here-anymore" about their time at Initech

    https://www.youtube.com/watch?v=yZjCQ3T5yXo

    "all right so when the subroutine compounds the interest, it uses all of these extra decimal places that just get rounded off. So we simplified the whole thing, we round them all down and drop the remainder... in to an account that we opened"

  • > Many people know that you shouldn’t do decimal calculations, such as those involving U.S. dollars and cents, with the floating-point numbers in most programming languages. This is because decimal numbers can’t be expressed exactly as such floating-point numbers, so you will encounter rounding errors.

    Decimals or pennies, you still have rounding errors. For example, if your contract is $100 / year. You will get the full $100 if you bill yearly, quarterly, or semi-annually. But if you bill monthly, no matter if you deal in pennies or fractional dollars, the sum total of your invoices for the year will be less than $100.

  • It's the 21st century: All computers should do Base10 math by default. We have cycles to burn, and some ARM and IBM CPUs even have decimal math instructions.

    Only true propellerheaded programmers should ever see or care about binary floating point issues. NB: I do massively scalable wireless data collection networks for IoT (using variously, floats, doubles, and half-precision, as called for by their use case), so I'm one of those people, but ordinary folks and users should never, ever, be impacted by binary imprecision.

  • > Many people know that you shouldn’t do decimal calculations, such as those involving U.S. dollars and cents, with the floating-point numbers in most programming languages. This is because decimal numbers can’t be expressed exactly as such floating-point numbers, so you will encounter rounding errors.

    Why not, rounding to the nearest cent is going to be much less precise for any realistic amount of dollars when using 64 bit floats (the type of float Javascript uses in every browser).

  • Accounting has the concept of materiality. But you still want the figures to tally to the last cent.

    One way to do this is to separate the computation/storage and presentation layer: use integers to store values as cents for computation/storage and only convert to dollars+cents on display. But then someone might suddenly demand three digits after the decimal point and you cannot go about changing every stored value just because the logic changed in one part of the application. So, using decimals is the safer choice.

    I prefer integers for my plain text ledger software though because the format is in my control.

Explore Birbla archives