Ridged mirror: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Addbot
m Bot: Migrating 1 interwiki links, now provided by Wikidata on d:q554112
en>Monkbot
 
Line 1: Line 1:
'''Q''' is a [[fixed-point arithmetic|fixed point]] number format where the number of [[Fraction (mathematics)|fractional]] [[bit]]s (and optionally the number of [[integer]] bits) is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits.  Q format is often used in hardware that does not have a floating-point unit and in applications that require [[fixed-point arithmetic|constant resolution]].
The title of the author is Figures but it's not the most masucline name out there. One of the issues she loves most is to do aerobics and now she is attempting to earn money with it. South Dakota is her birth location but she needs to move simply because of her family. For many years I've been operating as a payroll clerk.<br><br>Here is my blog post ... [http://www.ninfeta.tv/blog/66912 home std test kit]
 
==Characteristics==
Q format numbers are (''notionally'') fixed point numbers (but not actually a number itself); that is, they are stored and operated upon as regular binary numbers (i.e. signed integers), thus allowing standard integer hardware/[[Arithmetic logic unit|ALU]] to perform [[rational number]] calculations. The number of integer bits, fractional bits and the underlying word size are to be chosen by the programmer on an application-specific basis — the programmer's choices of the foregoing will depend on the range and resolution needed for the numbers. The machine itself remains oblivious to the notional fixed point representation being employed — it merely performs integer arithmetic the way it knows how. Ensuring that the computational results are valid  in the Q format representation is the responsibility of the programmer.
 
The Q notation is written as Q''m''.''n'', where:
*Q designates that the number is in the Q format notation — the [[Texas Instruments]] representation for signed fixed-point numbers (the "Q" being reminiscent of the standard symbol for the set of [[rational number]]s).
*''m'' is the number of bits set aside to designate the two's complement integer portion of the number, exclusive of the sign bit (therefore if m is not specified it is taken as zero).
*''n'' is the number of bits used to designate the fractional portion of the number, i.e. the number of bits to the right of the binary point. (If n = 0, the Q numbers are integers — the degenerate case).
 
Note that the most significant bit is always designated as the sign bit (the number is stored as a [[two's complement]] number) in order to allow standard arithmetic-logic hardware to manipulate Q numbers. Representing a signed fixed-point data type in Q format therefore always requires ''m''+''n''+1 bits to account for the sign bit. Hence the smallest machine word size required to accommodate a Q''m''.''n'' number is ''m''+''n''+1, with the Q number left justified in the machine word.
 
For a given Q''m''.''n'' format, using an ''m''+''n''+1 bit signed integer container with ''n'' fractional bits:
* its range is [-2<sup>''m''</sup>, 2<sup>''m''</sup> - 2<sup>-''n''</sup>]
* its resolution is 2<sup>-''n''</sup>
 
For example, a Q14.1 format number:
* requires 14+1+1 = 16 bits
* its range is [-2<sup>14</sup>, 2<sup>14</sup> - 2<sup>−1</sup>] = [-16384.0, +16383.5] = [0x8000,  0x8001 … 0xFFFF, 0x0000, 0x0001 … 0x7FFE, 0x7FFF]
* its resolution is 2<sup>−1</sup> = 0.5
 
Unlike [[floating point]] numbers, the resolution of Q numbers will remain constant over the entire range.
 
==Conversion==
 
===Float to Q===
To convert a number from [[IEEE 754|floating point]] to Q''m''.''n'' format:
# Multiply the floating point number by 2<sup>''n''</sup>
# Round to the nearest integer
 
===Q to float===
To convert a number from Q''m''.''n'' format to floating point:
# Convert the number to floating point as if it were an integer
# Multiply by 2<sup>−''n''</sup>
 
==Math operations==
Q numbers are a ratio of two integers: the numerator is kept in storage, the denominator is equal to 2<sup>''n''</sup>.
 
Consider the following example:
 
The Q8 denominator equals 2<sup>8</sup> = 256
 
1.5 equals 384/256
 
384 is stored, 256 is inferred because it is a Q8 number.
 
If the Q number's base is to be maintained (''n'' remains constant) the Q number math operations must keep the denominator constant. The following formulas shows math operations on the general Q numbers <math>N_1</math> and <math>N_2</math>.
 
:<math>\begin{align}
\frac{N_1}{d} + \frac{N_2}{d} &= \frac{N_1+N_2}{d}\\
\frac{N_1}{d} - \frac{N_2}{d} &= \frac{N_1-N_2}{d}\\
\left(\frac{N_1}{d} \times \frac{N_2}{d}\right) \times d &= \frac{N_1\times N_2}{d}\\
\left(\frac{N_1}{d} / \frac{N_2}{d}\right)/d &= \frac{N_1/N_2}{d}
\end{align}</math>
 
Because the denominator is a power of two the multiplication can be implemented as an [[arithmetic shift]] to the left and the division as an arithmetic shift to the right; on many processors shifts are faster than multiplication and division.
 
To maintain accuracy the intermediate multiplication and division results must be double precision and care must be taken in [[rounding]] the intermediate result before converting back to the desired Q number.
 
Using [[C (programming language)|C]] the operations are (note that here, Q refers to the fractional part's number of bits) :
 
===Addition===
signed int a, b, result;
result = a+b;
 
===Subtraction===
signed int a,b,result;
result = a-b;
 
===Multiplication===
// precomputed value:
#define K  (1 << (Q-1))
signed int      a, b, result;
signed long int  temp;
temp = (long int)a * (long int)b; // result type is operand's type
// Rounding; mid values are rounded up
temp += K;
// Correct by dividing by base
result = temp >> Q;
 
===Division===
signed int  a, b, result;
signed long int temp;
// pre-multiply by the base (Upscale to Q16 so that the result will be in Q8 format)
temp = (long int)a << Q;
// So the result will be rounded ; mid values are rounded up.
temp += b/2;
result = temp/b;
 
==See also==
{{Portal|Computer Science}}
*[[Binary scaling]]
*[[Fixed-point arithmetic]]
*[[Floating point]]
 
==External links==
* [http://www.superkits.net/whitepapers/Fixed%20Point%20Representation%20&%20Fractional%20Math.pdf Fixed Point Representation And Fractional Math] (Note: the accuracy of the article is in dispute; see discussion.)
 
[[Category:Computer arithmetic]]

Latest revision as of 05:10, 24 July 2014

The title of the author is Figures but it's not the most masucline name out there. One of the issues she loves most is to do aerobics and now she is attempting to earn money with it. South Dakota is her birth location but she needs to move simply because of her family. For many years I've been operating as a payroll clerk.

Here is my blog post ... home std test kit