2 questions about floating point and %

This is a discussion on 2 questions about floating point and % within the C Programming forums, part of the General Programming Boards category; Hello, I wonder if anyone can help me with two questions about floating point variables and modular arithmetic. How are ...

  1. #1
    ams80
    Guest

    2 questions about floating point and %

    Hello,

    I wonder if anyone can help me with two questions about floating point variables and modular arithmetic.

    How are floating point numbers (float or double) added together? I understand that the variables are stored as one bit for sign, so many for the exponent and the rest for the closest binary approximation to the number. When you add two numbers together how is the answer actually calculated? For example is the number with the smaller exponent adjusted so that the exponents are the same for each number and then the approximations added together? I'm interested in the errors generated with floating point arithmetic, does anyone know of a good online reference for this?

    Secondly, how does the % (modular arithmetic) operation calculate its answer? As in, to work out 10000%10 you could repeatedly subtract 10 from 10000 until the answer is less than 10. This would obviously be somewhat labour intensive so I'm interested in how it works. I'm wondering as I'm thinking about writing a function to find a%b for very large numbers.

    Thanks in advance for any answers,

    Andrew

  2. #2

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > Floats
    http://cch.loria.fr/documentation/IEEE754/

    > %
    Its usually a by-product of division

    > I'm wondering as I'm thinking about writing a function to find a%b for very large numbers.
    Perhaps here

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21