Fixed point versus floating point

I just can't understand fixed and floating point numbers due to hard-to-read definitions about them all over Google. But no one that I read provides a simple enough explanation of what they really are. Can I get a simple definition with an example?

+87
computer-science numbers
Sep 23 '11 at 5:53
source share
5 answers

A fixed-point number has a certain number of bits (or digits) reserved for the integer part (the part to the left of the decimal point), and a certain number of bits reserved for the fractional part (the part to the right of the decimal fraction). point). No matter how large or small your number is, it will always use the same number of bits for each serving. For example, if your fixed-point format was in decimal IIIII.FFFFF then the largest number you could imagine would be 99999.99999 and the smallest non-zero number would be 00000.00001 . Each bit of code that processes such numbers must have built-in knowledge of where the decimal point is.

A floating point number does not reserve a certain number of bits for the integer part or fractional part. Instead, it reserves a certain number of bits for a number (called the mantissa or significant) and a certain number of bits to tell where the decimal place (called the exponent) is in that number. Thus, a floating point number that occupied 10 digits with two digits reserved for the exponent could represent the largest value of 9.9999999e+50 and the smallest nonzero value of 0.0000001e-49 .

+114
Sep 23 2018-11-11T00:
source share

A fixed-point number simply means that there is a fixed number of digits after the decimal point. A floating point number allows a different number of digits after the decimal point.

For example, if you have a way to store numbers that require exactly four digits after the decimal point, then this is a fixed point. Without this restriction, it is a floating point.

Often, when a fixed point is used, the programmer actually uses an integer, and then assumes that some digits are behind the decimal point. For example, I could save two digits of accuracy, so a value of 100 means that it actually means 1.00, 101 means 1.01, 12345 means 123.45, etc.

Floating point numbers are a more general purpose, as they can represent very small or very large numbers in the same way, but there is little punishment for having extra storage for the place where the decimal point is.

+29
Sep 23 2018-11-11T00:
source share

From my point of view, fixed-point arithmetic is done using integers. where the decimal part is stored in a fixed number of bits or the number is multiplied by the number of decimal precision digits.

For example, if you need to store the number 12.34 , and after the decimal point we need only two precision digits, the number will be multiplied by 100 to get 1234 . When doing the math on this number, we will use this set of rules. Adding 5620 or 56.20 to this number will give 6854 in the data or 68.54 .

If we want to calculate the decimal part of a fixed-point number, we use the operand modulo (%).

12.34 (pseudo code):

 v1 = 1234 / 100 // get the whole number v2 = 1234 % 100 // get the decimal number (100ths of a whole). print v1 + "." + v2 // "12.34" 

Floating point numbers are a completely different story in programming. The current standard for floating point numbers uses approximately 23 bits for given numbers, 8 bits for exponent and 1, but for sign. See this link on Wikipedia for more information about this.

+3
Feb 21 '17 at 20:13
source share

The term โ€œfixed pointโ€ refers to the corresponding form in which numbers are presented, with a fixed number of digits after, and sometimes even before, the decimal point. With a floating point representation, the placement of the decimal point can โ€œfloatโ€ relative to the significant digits of the number. For example, a fixed-point representation with a uniform agreement on placing in a decimal point can represent numbers 123.45, 1234.56, 12345.67, etc., while a floating-point representation can additionally represent 1.234567, 123456.7, 0.00001234567, 1234567000000000, etc.

+2
Jun 18 '14 at 20:04
source share

Take number 123.456789

  • As an integer, this number will be 123
  • As a fixed point (2), this number will be 123.46 (Assume you have rounded it).
  • Like a floating point, this number will be 123.456789

A floating point allows you to represent most of the numbers with great accuracy. Fixed less accurate, but easier for the computer.

-four
Sep 23 2018-11-11T00:
source share



All Articles