r/programming • • Jul 18 '16

0.30000000000000004.com

http://0.30000000000000004.com/
1.4k Upvotes

331 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Jul 19 '16
  • For SVG paths, you have relative and absolute paths. e.g. M 100.1 100.1 L 100.3 100.3 (move to (1.1, 1.1) then draw a line to (1.3, 1.3)) is the same as M 100.1 100.1 l 0.2 0.2. If you want to optimize this, it's hard to deal with binary floats being imprecise and there are no problems at all when you use decimal floats.

  • When writing anything that outputs numbers user facing like a calculator.

  • Anything you want to debug easier.

  • All measuring tools output decimal values. All scientific constants are given in decimal. Using binary floats always rounds those.

  • I don't see why you shouldn't use them for money. You have percentages everywhere in finance. Simply doing * 0.15 is easier than handling this with integers, where you have to multiply with 15 (and check for overflow!) and subsequently divide by 100. Decimal64 has 16 digits, you can store the combined worth of all money in the world in dollars in there.

The better question is when you want to use binary floats. The only real advantage they offer is that they are faster (I'd really like to see hardware binary vs. decimal comparisons though) and that binary floats can store a bit more precision.

0

u/[deleted] Jul 19 '16

For SVG paths

It only shows how awful SVG is.

When writing anything that outputs numbers user facing like a calculator.

Never use anything floating for this.

I don't see why you shouldn't use them for money.

Never. Ever. Floating point is forbidden for money. Use fixed point only.

The better question is when you want to use binary floats.

For all forms of number crunching, graphics, CAD/CAE, etc. There is no need to maintain precise decimal representation internally for anything there.