Jump to content


Photo
- - - - -

Meaning of FXP "Word Length" vs "Integer Word Length"

fixed point maths

  • Please log in to reply
7 replies to this topic

#1 AlexA

AlexA

    Very Active

  • Members
  • PipPipPip
  • 196 posts
  • Version:LabVIEW 2010
  • Since:2007

Posted 14 March 2012 - 10:42 PM

Hi Guys,

Tinkering with my FPGA code today, I ran into a question which I'd never really contemplated before. Say I have an unsigned FXP number with word length = 1 and integer word length = 2. Labview tells me that this gives a maximum of 2 with a delta of 2, so the number can either be 0 or 2.

This makes no intuitive sense to me, the way I understood it, the word length is the total number of bits used to capture the number, the integer word length is the number of bits dedicated to capturing the integer portion, in other words, it kind of defines the "magnitude" of the number that can be captured, the remaining bits are used to give the "precision" to which the number is captured. So how is it even possible for the "integer word length" to be greater than the "word length"?

Insight much appreciated.

Cheers,
Alex
Posted Image

#2 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 622 posts
  • Location:Michigan
  • Version:LabVIEW 2012
  • Since:1994

Posted 14 March 2012 - 10:58 PM

I've not played with floating points for long enough that I'm blanking. Are they in the same units (i.e., both in bits)?
Tim

"If this was easy our kids would be doing it." - Coworker

#3 ned

ned

    Extremely Active

  • Members
  • PipPipPipPip
  • 466 posts
  • Location:Emeryville, CA
  • Version:LabVIEW 2012
  • Since:1999

Posted 14 March 2012 - 11:48 PM

I'm not sure why you'd do that, but it makes sense. Think of the difference between the integer word length and the word length as the power of 2 that a single bit represents. If your word length and your integer word length are both the same, that difference is 0, and a single bit represents 2^0=1 (a fixed-point value with an integer length equal to word length has no fractional portion). If the integer word length is 6 and the word length is 8, a single bit is 2^(6-8) = 2^(-2) = 0.25. In your case, you have an integer word length of 2 and a word length of 1, so a single bit represents 2^(2-1) = 2^1 = 2, which matches what LabVIEW is telling you: the number has 1 bit, which represents either 0 or 2.

Edited by ned, 14 March 2012 - 11:49 PM.

  • asbo likes this

#4 AlexA

AlexA

    Very Active

  • Members
  • PipPipPip
  • 196 posts
  • Version:LabVIEW 2010
  • Since:2007

Posted 15 March 2012 - 03:23 AM

Interesting way of looking at it Ned, thanks for the insight.
Posted Image

#5 bmouring

bmouring

    2 more posts to go.

  • NI
  • 8 posts
  • Location:Austin, TX
  • Version:LabVIEW 2012
  • Since:2008

Posted 01 June 2013 - 04:32 PM

The example that I keep tucked in the ol' noodle is the exceedingly bizarre situation of a FXP number with a WL of 1 and an IWL of -1024, meaning you have 1 bit to represent the value (so only two numbers in the range) and that they are the exceedingly small numbers around 0, so 2^-1024


"I have never let my schooling interfere with my education"
-Attributed to Samuel Clemens

#6 hooovahh

hooovahh

    Im no supervising technician Im a technical supervisor

  • Moderators
  • 1,419 posts
  • Version:LabVIEW 2013
  • Since:2004

Posted 03 June 2013 - 01:49 PM

If you are ever unsure of the range a number holds I just test it.  Put in a few numbers into both controls and then try to end numbers into the control to see the range and resolution.  I agree that the controls aren't labeled in an intuitive way but I can always test it to make sure it is working right.


"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin
"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd
"Using unofficial features of LabVIEW is cat nip laced with poison."
"3rd party VIs with block diagrams that are locked are useless. You see the problem all lies in the phrase "...if the VIs do what you want...". They typically don't and with locked diagrams you can't fix the problems." - Mike Porter
"If you really need a real-time system, then you really need a real-time system." - Hooovahh


#7 flintstone

flintstone

    Very Active

  • Members
  • PipPipPip
  • 50 posts
  • Version:LabVIEW 2010
  • Since:2011

Posted 03 June 2013 - 03:22 PM

You could also look at it as the position where the decimal point is set. If you have (word length == integer length) then you have the decimal point just after the last bit so this comes out as a normal integer. With your settings you get a single flip-flop which is interpreted as bit 1 of an integer, therefore you get the two values 0 = 0*2^1 and 2 = 1*2^1.


Waiting for the responding edition ...


#8 Dragis

Dragis

    One hit wonder!

  • NI
  • 1 posts
  • Version:LabVIEW 2011
  • Since:2000

Posted 22 July 2013 - 01:48 AM

For those interested in an in-depth look at fixed point, check out http://zone.ni.com/d...da/pub/p/id/303.