Just wondering how floating point arithmetic is implemented. The last time I heard this topic pop up on this site (maybe two months ago), people jokingly referred to it as "black magic" or "f---ing miracles." Seriously, how do they work?
now seriously. It's all up to the interpretation of bits. Basically you have a sign bit for the value. Bits for the value. Sign bit for the mantissa and bits for the manitssa. All in one
Sometime today I did a little doodling, and I think I've figured out how you'd represent a floating point number without sacrificing precision. Using base 256 (because that's the smallest unit of memory that a modern computer can handle without using special operators), you could represent a number like this:
Decimal: 123.456
Base 256: [123].[200][1]=123*256^0+200*256^-1+1*256^-2
The position of the decimal would be determined by another member of the struct.
The only reason I'm really asking this is because I'm interested in the bignum challenge, and thought I'd take a crack at it.
FP numbers are manipulated very much like integers, except that they are stored in sign-magnitude representation and have that pesky "exponent" part.
Multiplication is the same as any:
a = sa*ma*BEa
b = sb*mb*BEb
where s is the sign (-1 or 1), m is the mantissa (or integer value..), and E is the exponent value, which we use to raise the base B.
Multiplication is simple:
a * b = (sa*sb)*(ma*mb)*B(Ea+Eb)
Now, IEEE stipulates that the leading '1' bit for the mantissa is automagic -- it isn't actually stored in the mantissa itself. Likewise, the exponent is biased -- meaning that 0..(n/2)-1 is negative and n/2 to n is positive. (That is, the true exponent is E - n/2.)
As for you idea, I haven't the brainpower tonight to think about it.