# Board index » delphi » Floating point / fixed point

## Floating point / fixed point

What's the difference between these two?

## Re:Floating point / fixed point

##### Quote
Frederic wrote in message <3663EE27.88860...@rz-online.de>...
>What's the difference between these two?

Just what the name implies.  It is best described by an example:

1. Fixed point.

An example of fixed point representation will be an integer, or longint, or
word.  I all these types the position of the decimal point (binary point,
actually) is fixed.  In word, for example, the point is fixed to the right
of the rightmost bit, i.e. 32 bits are devoted to representing the integer
part of the number and 0 bits are devoted to representing the fractional
part of the number; obviously, you cannot store any fractions in a word.  It
does not have to be that way, though.  You can devote 20 bits to storing the
integer part and 12 bits to store the fractional part.  The point is, that
always exactly the same number of bits is devoted to storing the integer and
the fractional part of the number.  However, I do not know of any modern
standard that uses fixed-point representation to store non-integer numbers;
I think the primary reasons are
a.)wasted storage space
b.)complex multiplication/division
c.)complex comparisons (<,>)--although I am not sure about that one
d.) difficulty in representing very big or very small numbers

2. Floating point

After #1 this is pretty self-explanatory.  The binary point has no fixed
position, thus allowing for a much greater range of numbers to be
represented with greater accuracy.  Very big and very small numbers (I mean
numbers very close to 0, like 0.000000000000007) are much easier to
represent.  This representation allows to compare the numbers very fast, and
multiplication/division is easier, I think.  The classic example of a
floating-point representation is real.  Double and extended are also
floating point types; they are based on the same principle as real, just
allow for a wider range of numbers to be stored with greater accuracy.  The
"real" type is standardized by IEEE.  The standard number is IEEE 754  (IEEE
stands for International Electric Engineering something, I don't remember).

The way IEEE 754 (and larger types that are derived from this standard)
represent data can be found online, I am sure, or I can post it if anyone is
interested.

Nikita.

## Re:Floating point / fixed point

In article <3663EE27.88860...@rz-online.de>,

##### Quote
Frederic  <frede...@rz-online.de> wrote:
>What's the difference between these two?

The name says it all. In floating point the position of the point can
float, ie. one can express different numbers within some range like
10^-38..10^38 with precision of specific number of digits, like 10. One
can for example present numbers: 123, 1.23, 0.123 etc. Note, however,
that the internal representation is not necessarily accurate as
computers typically use binary representation.

In fixed point numbers the decimal point is at fixed position, i.e. there
are fixed number of decimals. There could also be always two decimals
which is good for financial calculations. (An alternative version of
fixed point numbers uses binary representation i.e. there is fixed
number of bits on the right side of the decimal point)

Turbo Pascal does not directly support fixed point numbers though one can
implement them with for example comp type. You need to write your own IO
and possibly multiplication/division.

Osmo

## Re:Floating point / fixed point

In article <7FT82.2225\$5n1.17758...@news.magma.ca>,

##### Quote
Nikita Synytskyy <nik...@NOSPAMmondenet.com> wrote:
>  However, I do not know of any modern
>standard that uses fixed-point representation to store non-integer numbers;
>I think the primary reasons are
>a.)wasted storage space
>b.)complex multiplication/division
>c.)complex comparisons (<,>)--although I am not sure about that one

Comparing fixed point numbers is like comparing integers.

##### Quote
>d.) difficulty in representing very big or very small numbers

Note that a fixed point number can also be based on decimal system. This
IMO is more useful as real life is based more on decimals, like hundredths
of a currency unit.

##### Quote
>2. Floating point

>After #1 this is pretty self-explanatory.  The binary point has no fixed
>position, thus allowing for a much greater range of numbers to be
>represented with greater accuracy.  Very big and very small numbers (I mean
>numbers very close to 0, like 0.000000000000007) are much easier to
>represent.  This representation allows to compare the numbers very fast, and
>multiplication/division is easier, I think.  The classic example of a
>floating-point representation is real.  Double and extended are also
>floating point types; they are based on the same principle as real, just
>allow for a wider range of numbers to be stored with greater accuracy.  The
>"real" type is standardized by IEEE.  The standard number is IEEE 754  (IEEE
>stands for International Electric Engineering something, I don't remember).

The real type is Borland invention. The other types are standard.
The real type is 6 bytes so the RTL routines can process with
registers, holding one real in DX:BX:AX and another in DI:SI:CX. With
larger types one would run out of registers as there only is BP and SP
left.

Osmo

## Re:Floating point / fixed point

In article <7FT82.2225\$5n1.17758...@news.magma.ca>, Nikita Synytskyy
<nik...@NOSPAMmondenet.com> writes

##### Quote
>"real" type is standardized by IEEE.  The standard number is IEEE 754

I think this is the one where the mantissa begins at the SECOND most
significant digit (the first being discarded). After all, in binary, if
the first significant digit is always a "one" then why bother storing
it? Might as well spend the space on extra precision. I remember falling
thought of it first!

Regards -

--
Marcus Morris - South Croydon, LONDON, UK (Mar...@ntos.demon.co.uk)

## Re:Floating point / fixed point

On Thu, 3 Dec 1998 04:44:12 +0000, Marcus Morris

##### Quote
<Mar...@ntos.demon.co.uk> wrote:
> In article <7FT82.2225\$5n1.17758...@news.magma.ca>, Nikita Synytskyy
> <nik...@NOSPAMmondenet.com> writes

> >"real" type is standardized by IEEE.  The standard number is IEEE 754

Turbo/Borland Pascal's REAL type is not standardized by IEEE. The
standardized types are SINGLE, DOUBLE and EXTENDED (IEEE 854). They
are implemented in TP/BP according to the standard because the INTEL
copros implement them.

##### Quote
> I think this is the one where the mantissa begins at the SECOND most
> significant digit (the first being discarded).

Not really. The MSB is the sign bit in almost every binary FP
representation.

For DOUBLE the layout is similar.

TP REAL (48 bits)

47             sign
8..46          39 bit mantissa (implicit '1.' not stored)
0..7           8 bit biased exponent (range 0..\$FF, bias \$81)

DOUBLE

63             sign
52..62         11 bit biased exponent (range 0..\$7FF, bias \$3FF)
\$7FF denotes NANs or INIFINITY
0..51         52 bit mantissa (implicit '1.' not stored)

Interpretation:

value = 2^(exponent-bias) * (1 + mantissa/2^(sizeof_mantissa))

exponent=0  REAL : 0.0  (mantissa is ignored)
DOUBLE:
if mantissa = 0 then value=0.0
if mantissa <> 0 then
value = 2^(1-bias) * mantissa/2^(sizeof_mantissa)
(denormalized value)

Regards
Horst