Re: bignum with floating point



banansol@xxxxxxxxxxxx wrote:

I want to program a bignum library in C just for learning,
it doesn't seem too hard (I don't care about speed) when
considering just integer numbers, but when I add support
for division and need floating point numbers I doesn't
look so easy anymore. I wonder if it's hard to do this.
Is there some easy trick to do this? Can I just round
off some fixed digits to the right of the decimal-point?
Or do I need to get a deep understanding of
floating point representations and IEEE standards?

You don't need to understand IEEE standards, but it helps to understand the fundamentals of floating point. Instead of integers, think of fixed-point values with the binary point to the left of the most-significant bit: 0.xxxxx, where xxxxx is an arbitrary binary value to any desired length. Select an exponent base, add a sign bit and multiply by a power of base and you have a floating point representation:
-1**s * 0.xxxxxx... * base**e.

For IEEE base = 2, but other bases are possible. Older-design IBM computers used a base of 16. You might want to use a base of 256 to minimize bit shifting at the expense of a few wasted bits (less important for longer formats).

If the leading base digit in the mantissa is non-zero, the representation is normalized: 0.1xxxx... for base = 2.

Normally, floating point operations start with normalized values. Multiplication and division are straight-forward. Addition and subtraction require that you first shift an operand to align the base point of the two operands. If you use base = 256 on an 8-bit unsigned char machine, you can get the same results by selective indexing, rather than actual shifts. After the addition or subtraction, the results should be normalized.

--
Thad
.



Relevant Pages

  • Re: How do you keep track of what all the numbers mean?
    ... that if you develop a floating point representation of a system, ... but I would suspect that scaling constants is a main part of it. ... There will be an assumed scaling between the floating point ... will depend upon the input signal power. ...
    (comp.dsp)
  • Re: Rounding of the double
    ... John von Neumann suggested that only fixed-point integers should be used because floating ... If you choose your representation as double, then you have to live with the consequences. ... you can never get precision in any computation on a computer than involves ... MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text - ...
    (microsoft.public.vc.mfc)
  • Re: This calculation is just wrong / computer cant count!
    ... we have is the binary representation of the computer. ... your delusional system of mathematics, one based on a decimal arithmetic model, is ... "ignore" any aspect of floating point precision. ... "I do not wish to deal with the inherent inaccuracy of double precision floating point. ...
    (microsoft.public.vc.mfc)
  • Re: Gentler Decimal Floating-Point
    ... effectively change the radix of a decimal floating point ... under the heading "Logarithms all the time", ... logarithmic representation of numbers to be made workable for all the ... The middle digits are shifted only when the exponent, ...
    (comp.arch.arithmetic)
  • Re: How do you keep track of what all the numbers mean?
    ... that if you develop a floating point representation of a system, ... but I would suspect that scaling constants is a main part of it. ... There will be an assumed scaling between the floating point ... So, in my LMS equalizer example, if my floating point equalizer input ...
    (comp.dsp)