|
|
> By the way, I may need a lecture on computer float representation and
> binaries ...
Floating point in computers means floating point binary.
You may be familiar with binary integers...
the first bit is one, the next two, the next four, then eight,
16, 32, 64 128 etc. So for example you could represent
the number three in binary as a byte 00000011
But binary fractions go 1/2, 1/4, 1/8, 1/16, etc
At some point the fraction repeats, but in a computer
it just gets truncated after some point.
So 1/3 ends up 0.01010101...
An interesting part of this is that any fraction that has a
denominator with a factor other than 2 repeats, and
therefore exhibits a small amount of error. You can
look at the actual floating point bits online.
http://www.h-schmidt.net/FloatApplet/IEEE754.html
There's one bit for the sign, 8 bits for the exponent,
and 23 bits for the numbers.
The easiest way to get better accuracy is to use integers
where you can.
Post a reply to this message
|
|