Shop OBEX P1 Docs P2 Docs Learn Events
Faster fractional multiply — Parallax Forums

Faster fractional multiply

Bobb FwedBobb Fwed Posts: 1,119
edited 2011-07-12 09:10 in Propeller 1
I want to multiply a 16-bit number by 1.054. Is there a faster way to do it other than float math and not using any additional cogs.

Comments

  • ericballericball Posts: 774
    edited 2011-07-12 08:55
    Yes. Use fixed point.


    Use PhiPi's solution. I always forget that SPIN uses signed values. (Plus his is probably slightly faster anyway.)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-12 09:04
    Similar to Eric's:
    y += y ** 231928234   'Multiply y by 1.054
    

    This multiplies y by 0.054 * 232, returning the high 32 bits, then adds the result to y (i.e. the "1" part).

    -Phil
  • AleAle Posts: 2,363
    edited 2011-07-12 09:05
    Well... if you use a 16.16 format, and multiply by 1.0000110111010010 then you get a passable approximation (1.0539856) :)

    result = (x << 16) * $1_0DD2
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-07-12 09:10
    Gives me negative numbers ('cause the "fraction" is signed).

    Changed it to
    result := input << 2 ** $4374_BC6A
    
    Thanks!
Sign In or Register to comment.