Re: floating-point float

From: William L. Bahn (william_at_toomuchspam.net)
Date: 03/21/04


Date: Sat, 20 Mar 2004 20:48:38 -0700


"andy" <andy_wil@dot.com> wrote in message
news:cV67c.416$tY6.7548@bgtnsc04-news.ops.worldnet.att.net...
> For a float-point float, how to know in C code where the decimal point
> locates?
>
> Why are float in C code different from fixed-point float?
>
> If defining fixed-point floats in 16.16 format, does this mean that all
> these fixed-point floats can not represent negative floats?

You seem to be struggling primarily because of a fundamental lack of
understanding of how numbers can be represented - regardless of whether it
is C or you are writing them on a piece of paper.

Independent of a computer language, what you are calling "float" you
probably should be calling "real". For this discussion, the two
classification of numbers are "integer" and "real" where the primary
difference is that reals are the sum of an integer and a fractional part.
Given a real number, we have to decide how to represent it in a certain
number of bits if we want to use it in a computer program and, in general,
we are free to do that however we want to and we will be okay as long as we
use our representation consistently and it poses no fundamental roadblocks
to performing the operations we wish to perform. Two common ways of
representing real values is using a fixed-point representation and using a
floating-point representation. The fixed point representation is based on
having a known and fixed location within our representation where we assume
the radix point is located. In a floating point representation we generally
take an approach akin to writing a number in exponential notation where we
have a mantissa and an exponent. The exponent contains the information about
where the radix point is located relative to the mantissa.

Most languages, such as C, have at least one means of representing real
values and a huge advantage of using that representation is that you (in
most circumstances) don't have to deal with the representation - the people
that wrote the compiler did all of that for you and as long as you use their
operators and their functions as intended you will be fine. The
representation that C compilers use is a very specific floating point
representation. If you want to use a fixed point representation, then you
are responsible for developing it (or learning about one that someone else
has developed) and implementing it and being sure that you are consistent in
its use. That's quite a bit of overhead and is seldom worth it. But there
are certainly circumstances where the benefits are worth the costs.



Relevant Pages

  • Re: Float comparison
    ... If a double object x contains the value 42.0, it doesn't matter ... Look at the hex representation of 1.0. ... Yes, because there are an infinite number of reals in the 'range', ... assume we are talking about the float type. ...
    (comp.lang.c)
  • Re: Convert float to double - weird failure
    ... bill robertson wrote: ... Float 1.2 is uninterpreted hex 0x3f99999a ... It's converting the float representation of 1.2 which is 0x3f99999a to a double representation which is not even 0x3f99999a00000000. ... unsigned int mantissa:23; ...
    (comp.programming)
  • Re: strong/weak typing and pointers
    ... unintentionally got people upset before. ... your float struct doesn't have get_sign, ... ;) You're still dealing with the same representation, ... If the top 2 or 4 bytes can specify multiple interpretations ...
    (comp.lang.python)
  • Re: float -> double
    ... Let us take a float with the hexadecimal representation 0x3f800001. ... When converting to double, we get another 29 bits of precision, which means we can theoretically convert this number to any one of 536,870,912 possible representable numbers in the range. ... The exact value could be printed if you really wanted to, but there's no real point since the implicit error in the number dwarfs most of the latter digits. ...
    (comp.lang.java.programmer)
  • Re: Float comparison
    ... My point, however, is that the float value stored in x corresponds to ... Only Keith's had the unique property of exact equality in the reals. ... I did miss the point Keith makes about the representation of the value of a float being exactly real and a fraction whose denominator is a power of 2. ... I was concerned with 'close enough' for the conversions to work, not with the mathematical exactness of anything. ...
    (comp.lang.c)