Shop OBEX P1 Docs P2 Docs Learn Events
Fixed-point math Number to Interger — Parallax Forums

Fixed-point math Number to Interger

UltraLazerUltraLazer Posts: 30
edited 2011-12-09 12:49 in Propeller 1
What the fastest way to convert a fixed point number ("Fixed-point math with trig functions in SPIN" from obex) to an Integer?

Right now I am converting the number to a string with .QvalToStr then from string to integer with a hacked piece of code. this takes far too long.

sub Question (may answer question one): How a the fixed point number encoded in 32bits?

Thanks

Comments

  • cessnapilotcessnapilot Posts: 182
    edited 2011-12-04 01:53
    Hi UltraLaser,

    In case of the integer part, simply shift the number 16 times to right.

    In case of rounding add 0.5 to the number (= 2^15) to it and take the integer part.

    The MS 16 bit are for the signed integer part, the LS 16 bits are for the fraction.

    Cheers,

    Istvan
  • UltraLazerUltraLazer Posts: 30
    edited 2011-12-09 12:49
    Thanks cessnapilot, sorry for the delay. This is exactly what I was looking for.
Sign In or Register to comment.