News for hackers. Stuff that matters.
Re:Can we trust floating-point numbers? (2006) [pdf] by lmm on Tuesday September 16, 2014 @12:02PM (#8325165)
I've long wanted a language that defaults to a decimal type (or perhaps forces the user to specify a precision), and provides hardware floating point only as an option where requested. Something like the way Python handles integers.

Most of what C-family languages do has the wrong semantics. Any program which is happy to accept round-to-even and arbitrary increases in precision would probably accept the rearrangement of arithmetic under the assumption that it was commutative, but in e.g. Java there's no way to change rounding mode, and also no way to just request an approximate answer. The defaults are a compromise that satisfies no-one.

Re:Can we trust floating-point numbers? (2006) [pdf] by ori_b on Tuesday September 16, 2014 @01:36PM (#8325753)
The problem is that decimal types don't make things any better, at least when you have finite precision. They have the same problems with rounding error. The error analysis is exactly the same when designing your algorithms, only in a different base.

The only thing that they make easier is parsing and displaying numbers. The number of times where you deal with things that are guaranteed to be perfectly represented by powers of ten are relatively few.

Re:Can we trust floating-point numbers? (2006) [pdf] by acqq on Tuesday September 16, 2014 @01:44PM (#8325819)
> The number of times where you deal with things that are guaranteed to be perfectly represented by powers of ten are relatively few.

For a physicist, a few. For an accountant, all.

Re:Can we trust floating-point numbers? (2006) [pdf] by dragonwriter on Tuesday September 16, 2014 @12:43PM (#8325411)
> I've long wanted a language that defaults to a decimal type (or perhaps forces the user to specify a precision), and provides hardware floating point only as an option where requested.

Scheme (via its numeric tower) and some other language default to exact types (decimal or in some cases rational if they don't have a separate exact decimal type) and only use approximate floating point types if explicitly requested (including using by using a function which inherently produces an approximate output.)

Haskell can be configured by way of the default specifier to do something analogous to this in its handling of ambiguous numeric types (which includes literals, which start out with a generic type of Num a => a) , though the default default uses double precision floating point for types that can't be constrained to arbitrary precision integers -- default (Integer, Double) -- so to do this you need something like default (Integer, Rational, Double.)

Re:Can we trust floating-point numbers? (2006) [pdf] by carterschonwald on Tuesday September 16, 2014 @12:47PM (#8325437)
In haskell, every literal is constructed via an Integer (big int) or Rational, which is then converted into the final representation. (roughly). I'm actually slowly doing some auditing of GHC Haskell's floating point machinery as I find the time.
Re:Can we trust floating-point numbers? (2006) [pdf] by dragonwriter on Tuesday September 16, 2014 @12:55PM (#8325470)
That makes sense as the underlying implementation approach, but I was more referring to the "final" representation (I've also edited the description as it regards Haskell with more details, since its not really about literal handling specifically, though that's subsumed within it.)