Shop OBEX P1 Docs P2 Docs Learn Events
Question about division?? — Parallax Forums

Question about division??

James LongJames Long Posts: 1,181
edited 2007-01-01 20:50 in Propeller 1
Ok....Mike...I know you will answer....but anyone else can as well.

Say I want to divide some moving data.

I don't necessarily care about the information below the decimal.

Will the propeller divide a mathematical problem that will result in a Floating point result? (without using a floating point calculation)

If so....what will be the result?

If not....well we know the answer to that don't we.

Thanks,

(especially Mike...... if you answer)

James L

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-01 19:07
    There have been some division routines posted by Chip for the Propeller which divide a 32 bit dividend by a 16 bit divisor to give a 16 bit quotient and 16 bit remainder. Look for a posting called "Propeller Guts" for this. This can be easily modified to use a 32 bit divisor to give a 32 bit quotient and 32 bit remainder. There are no routines (other than in the floating point package) that will give a floating point result. The assembly floating point routines are quite fast and can convert a 32 bit integer to floating point for division if that's what you really want.
  • James LongJames Long Posts: 1,181
    edited 2007-01-01 20:24
    Mike,

    So...as I read it....if it is not a whole number result, the calculation wouldn't work.

    But I'll look for the Propeller guts posting.

    Thanks Mike...(as usual)

    James L
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-01 20:50
    You do get a remainder. You can also scale the dividend before division if you want a fixed point fraction. For example, you could shift the dividend left 3 bits before division. Your quotient and remainder would be in 1/8ths. If you want to scale the dividend by 10 (to get a quotient and remainder in 10ths), you can multiply by 10 as follows:
         mov   temp,dividend
         shl     temp,#2           ' multiply by 4
         add    dividend,temp   ' add to get * 5
         shl     dividend,#1      ' multiply by 2 to get * 10
    
    
Sign In or Register to comment.