Floating point - please enlighten me!


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Gee, and you question SO looked like you needed to multiply a whole number by .2235 and the .2235 was where the trouble is. If you need .00044*.2235, thats a different problem. You are correct, your question was simplified.Where are you getting numbers like .00044 in your pic? how is that generated?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Nov 2010
    Posts
    8


    Did you find this post helpful? Yes | No

    Question Just trying to learn how to use work around in PIC of Decimal values

    Quote Originally Posted by cncmachineguy View Post
    Gee, and you question SO looked like you needed to multiply a whole number by .2235 and the .2235 was where the trouble is. If you need .00044*.2235, thats a different problem. You are correct, your question was simplified.Where are you getting numbers like .00044 in your pic? how is that generated?
    Hello

    Thanks

    I am just trying to understand the work around format in PIC to work with floating point values, the systems I normally program have floating point at part of there normal stucture.

    I though from the orignal post that all you needed to do is use fractions in your formula and it would work but it does not seem to be so.

    For example If I needed to multiply some varriable by .234 or any decimal value to get an answer, how would this be done?

    In my case I am takeing a analog voltage and turning in into a tempature that is displayed on a screen.

    The temperature result does not need to be floating point

    But if I can not use floating point numbers to scale correctly the value could be off by 5+- degrees pretty quickly

    The true formula is

    result=adc10((adc10*.00034)+.2235) 'where adc10 in the pic 10 analog register

    To be within 1% of the true tempature

    Thanks

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark30504 View Post
    The true formula is

    result=adc10((adc10*.00034)+.2235) 'where adc10 in the pic 10 analog register

    To be within 1% of the true tempature

    Thanks
    so plugging in extremes:
    adc10=1 gives us
    result=1((1*.00034)+.2235)=1(.00034+.2235)=1(.2238 4)=.22384
    adc10=1023 gives us
    result=1023((1023*.00034)+.2235)=1023(.34782+.2235 )=1023(.57132)=584.46036

    Is this correct? Seems like quite a lot of work to scale an answer. what temps do the extremes represent?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Back up to post #8

    The constants
    .00034
    .2235

    Would be changed to
    34
    223

    In your formula.
    Then at the end you would divide by a power of ten.
    If all of this fits into the variable type used
    BYTE
    WORD
    LONG
    then the result will be truncated to an integer.
    Truncating to an integer is what you wanted...
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts