Re:What every computer programmer should know about floating...
by groby_b on Monday September 15, 2014 @11:43PM
(#8322922)
They might seem dumb, but on closer look IEEE754 (which is what you probably mean when you say float) is a pretty clever piece of engineering.
Here's a great bit of info, interviewing professor Kahan (one of the principals behind it) http://www.cs.berkeley.edu/~wkahan/ieee754status/754story.ht...
Believe me, they might be painful, but they're definitely one of the least painful ways to handle non-integer values.
Re:What every computer programmer should know about floating...
by acqq on Tuesday September 16, 2014 @03:49AM
(#8323467)
Without trying or thinking people just don't expect the effects which have sense once you know what is actually going on:
void p( int i ) {
float f = i;
int i2 = f;
printf( "%d\n%f\n%d\n\n", i, f, i2 );
}
int main() {
p( 0x7fffffbf );
p( 0x7fffffc0 );
}
/*
prints
2147483583
2147483520.000000
2147483520
2147483584
2147483648.000000
-2147483648
*/
I wouldn't call the behavior dumb, nor would I involve hate. You get the results that correspond to what you programmed, not what you wish to happen and what would actually not be feasible, as long as you insist on using float.
Re:What every computer programmer should know about floating...
by brucedawson on Tuesday September 16, 2014 @11:27AM
(#8324958)
The round-tripping behavior is certainly cool, but my favorite float-fact is still this one:
double pi = 3.14159265358979323846; printf("pi = %.33f\n + %.33f\n", pi, sin(pi));
sin(double(pi)) is equal to the error in the double(pi) constant. If you manually add the two you can easily get pi to about 34 digits. Useless, but cool. I discuss this in more detail here: http://randomascii.wordpress.com/2012/02/25/comparing-floati...
Re:What every computer programmer should know about floating...
by forrestthewoods on Tuesday September 16, 2014 @11:47AM
(#8325062)
if I didn't encounter it personally it can't possibly be my favorite
Re:What every computer programmer should know about floating...
by chewxy on Monday September 15, 2014 @11:56PM
(#8322948)
Come up with something that can represent every number then? IEEE754 may be a pain in the ass, but dumb is not a word I'd use to describe it
Re:What every computer programmer should know about floating...
by ygra on Tuesday September 16, 2014 @01:28AM
(#8323197)
The problem is, I guess, that people assume that floating-point numbers represent real numbers and behave like those. But while they're an often useful approximation, they are governed by very different laws. The same holds for integers in computers (except bigints), but the only place where they bite you is overflow and not by unexpected behaviour over the whole range of numbers.
Floats are dumb. I use them every day but they're dumb and I hate them! <grumble>