Re: float vs. double?
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Dec 2006 07:17:33 -0000
"Robert Wong" <robertwong@xxxxxxxxxxx> wrote in message
news:OK%23gpmGJHHA.1252@xxxxxxxxxxxxxxxxxxxxxxx
I wasn't sure if it was a code generation problem. Also kind of weird is
depending on the variable type, is different precision being stored?
Of course - "double" is called "double" because it stores about twice as
many significant figures as "float".
FORTRAN is a bit more verbose "float" = "REAL" and "double" = "DOUBLE
PRECISION".
The same multplication is used.
answer = value * lsb; // debugger - 1004714.7 float
danswer = value * lsb; // debugger - 1004714.7080078125 double
It is also worth noting that multiplication essentially preserves the number
of significant figures - the result will be accurate to the number of
significant figures as the less accurate of the multiplicands. [And note
that integers are first converted to float or double when multiplied by
float or double.]
But lesson number 1, which I learned in FORTRAN IV in my first lesson (in
1968), is "never use single precision" as you're laying yourself open to
errors which can be mitigated just by using double precision. Since then I
don't think I have ever done any floating point computation in single
precision - and these days, as I say, (because of me, obviously, and
possibly the other David too <g>) Mr Intel designs his chips to work most
efficiently in double precision.
If you're going to be doing a lot of floating point computation, I'd
seriously recommend looking at a textbook or two on numerical maths. [I'd
recommend those on my shelves but they've probably been out of print for 30
or 40 years.]
Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
.
- Follow-Ups:
- Re: float vs. double?
- From: Joseph M . Newcomer
- Re: float vs. double?
- References:
- float vs. double?
- From: Robert Wong
- Re: float vs. double?
- From: David Webber
- Re: float vs. double?
- From: Robert Wong
- float vs. double?
- Prev by Date: modal dialog does not give back control
- Next by Date: Re: why and how to create resource dll in MFC?
- Previous by thread: Re: float vs. double?
- Next by thread: Re: float vs. double?
- Index(es):
Relevant Pages
|
Loading