Thread: Flaoting to Integer conversion

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    38

    Flaoting to Integer conversion

    Hello All,

    I have timer interrupt routine wherein I need to do some floating point operation. There is no floating point processor in system. It is basically an embedded system.

    If I do floating point operation in interrupt routine, it is heavy overhead for processor.

    Can I do same operation but with similar accuracy using integers?

    Please advise..
    Juganoo

  2. #2
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    You might try fixed point numbers.

    What you do, is you set aside a number of binary digits in an integer for the decimal point accuracy. ie:

    32 16 8 4 1 | decimal point | 1/2 1/4 1/8 1/16 1/32

    Addition and subtraction of fixed point numbers are just the same as that for regular integers. When you divide a fixed point number by another, multiply it by `1' (whatever that is in your system). When you multiply a fixed point number by another, divide it by `1' (again, what it is in your system.) It's great, because both of those operations are bitshifts.. You might try google or programmersheaven to get more help with this.
    .sect signature

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    see my sig for an example of fixed point arithmetic instead of floating point to compute a pwetty mandelbwot fwactal
    hello, internet!

  4. #4
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    bill cosby?
    .sect signature

  5. #5
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by ggs
    bill cosby?
    ??????
    hello, internet!

  6. #6
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    bleh. I saw that _very_ program posted on another board, I SWEAR. but it made a fractal out of ``bill cosby''. Are you stealing SORES from somewhere..?
    .sect signature

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    i can assure you 105% that this program is an original creation by me. just because you saw another program that was a whole bunch of code smashed into four lines doesnt mean much
    hello, internet!

  8. #8
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    well, a few more similarities than that (ie, output... ;O) but on second look yes, the code is very different shocking, that... 105%, you say? whee

    lor~, i apologize for teh outburst
    Last edited by ggs; 11-12-2002 at 08:20 PM.
    .sect signature

  9. #9
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by ggs
    well, a few more similarities than that (ie, output... ;O) but on second look yes, the code is very different shocking, that... 105%, you say? whee
    well, the fractal is a "standard", that many people can code in their sleep.
    hello, internet!

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    38
    MOI , can you explain me, how it works??/

    Jgnoo

  11. #11
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    uggggggg............

    you start out with a sane looking program, replace all the variables with single letters, optimize your code as much as possible for terseness, remove all whitespace, and voila. its really not all that amazing
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM