Float2Fract and Fract2Float sillyness

Discussion in 'Embedded Systems and Microcontrollers' started by dannybeckett, Nov 7, 2012.

  1. dannybeckett

    Thread Starter Senior Member

    Dec 9, 2009
    Hi there.

    I am getting some strange behaviour from Float2Fract and Fract2Float.


    The only successful tests were 1, 3 and 5. In the first, (Fract2Float), a float is passed to the function (which I would assume it would want a fractional type passed to it) and returns a float. The returned value is scaled between -1 and 1 from -32768 and 32767 (This would make more sense if this function was Float2Fract???)

    In the third, I passed Float2Fract a float value in the normal float range and it gave me a fractional back with the value of 32767 (max. float value, I thought a fractional type could only be between -1 and + 0.9999???)

    In the fifth, I passed Float2Fract a float value of 0.45806885 which came back as fractional 15010, which is the correct scale up of the first test.

    I am confused and I must be doing something stupid! Please enlighten me about floats, fracts and what should be going in and coming out of these functions

    Thanks a lot