By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

why is double more efficient than float ?

P: n/a
hello ,
i would like to know as to why double is more efficient than float .
thanking you,
ranjan.

Nov 15 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
maadhuu wrote:
i would like to know as to why double is more efficient than float .
thanking you,


That statement is useless without much more context.

Uli

Nov 15 '05 #2

P: n/a
"maadhuu" <ma************@yahoo.com> wrote in message
news:7f******************************@localhost.ta lkaboutprogramming.com...
hello ,
i would like to know as to why double is more efficient than float .


What is the efficiency you're talking about?

If it's precision and range, then the answer is obvious, because double has
more bits in mantissa and exponential.

If it's the speed, then either your compiler or the CPU/FPU does some extra
job to support float. It maybe that double is native (or more native than
float) for the compiler or CPU/FPU.

Alex
Nov 15 '05 #3

P: n/a
maadhuu wrote:
i would like to know as to why double is more efficient than float .


It is not, at least not in general.
On modern platforms, there is hardware that supports floating point
operations in a precision suitable for double, often with 32 bit float
and 64 bit double types. You save nothing on using float, except memory,
but the lack of precision in float will give you problems soon enough.
Some of these platforms even need more time working with floats as
they work internally with double precision and have to do additional
conversions for float.
Note, however, that it is perfectly possible that an implementation
provides float and double which use the same size and representation.

If your platform does not support floating point maths in hardware,
then usually double operations will take more time. For example, on
the Amiga (with MC68000 CPU) one had mathieeesingbas.lib and
mathieeedoubbas.lib IIRC where the IEEE double precision took more
memory and time.

In a way, however, double is the "natural" floating point type for C:
All floating point constants are a priori double constants unless
you qualify them as float or long double (1.0 vs 1.0F and 1.0L).
The mathematical functions from the standard library have the short
name intended for double and have an additional 'f' or 'l' in the
name to mark the float/long double versions.
The semantics in K&R C pointed even stronger towards that (the
remains can be found in the behaviour of arguments to functions
without prototype or variable argument lists).
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #4

P: n/a
maadhuu wrote:
I would like to know as to why double is more efficient than float.


Who told you that it was?
Nov 15 '05 #5

P: n/a
In article
<7f******************************@localhost.talkab outprogramming.com>,
"maadhuu" <ma************@yahoo.com> wrote:
hello ,
i would like to know as to why double is more efficient than float .
thanking you,
ranjan.


Is it?
Nov 15 '05 #6

P: n/a
This question is probably not appropriate to this forum as it deals
with issues that are specific to a given Floating Point implementation
and this forum deals with the C programming language.

In any evnt, maadhuu, you would need to provide more specific
implementation -- namely a specific Floating Point implementation
(vendor, model #, etc.), and then direct your question to the
appropriate forum.

Nov 15 '05 #7

P: n/a
Alexei A. Frounze wrote:
"maadhuu" <ma************@yahoo.com> wrote:
i would like to know as to why double is more efficient than float .
What is the efficiency you're talking about?

If it's precision and range, then the answer is obvious, because double
has more bits in mantissa and exponential.


There is no C language requirement for this. Indeed, there are many
implementations where float, double and long double have the same
representation.
<snip>


--
Peter

Nov 15 '05 #8

P: n/a
Simon Morgan <si***@16hz.net> writes:
On Wed, 14 Sep 2005 14:08:30 -0400, maadhuu wrote:
i would like to know as to why double is more efficient than float .
thanking you,


Do your own homework.


If that's homework, it's a lousy question.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9

P: n/a
On Thu, 15 Sep 2005 18:24:24 +0000, Keith Thompson wrote:
If that's homework, it's a lousy question.


Agreed. But why else would he be asking it? Either he read it somewhere in
which case there would no doubt be an explanation or if it was some forum
he'd have posted a reply. If it's something that somebody told him then he
would have just asked them to qualify the statement. Look at all the other
questions he's posted and it seems pretty obvious that he expects the
group to do his homework for him.

--
"Being a social outcast helps you stay concentrated on the really important
things, like thinking and hacking." - Eric S. Raymond

Nov 15 '05 #10

P: n/a
Simon Morgan wrote:
On Thu, 15 Sep 2005 18:24:24 +0000, Keith Thompson wrote:
If that's homework, it's a lousy question.


Agreed. But why else would he be asking it? Either he read it somewhere in
which case there would no doubt be an explanation or if it was some forum
he'd have posted a reply. If it's something that somebody told him then he
would have just asked them to qualify the statement. Look at all the other
questions he's posted and it seems pretty obvious that he expects the
group to do his homework for him.


However, it may be that he got this particular flea here, maybe
even from me: I regularly tell people using modern desktop computers
that they probably will fare far better with double. If worded poorly
or incautiously, something like that will lead to the misconception
that double is always and in all respects better/more efficient than
float.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #11

P: n/a
In article <3o************@individual.net>,
Michael Mair <Mi**********@invalid.invalid> wrote:
However, it may be that he got this particular flea here, maybe
even from me: I regularly tell people using modern desktop computers
that they probably will fare far better with double. If worded poorly
or incautiously, something like that will lead to the misconception
that double is always and in all respects better/more efficient than
float.


It's one of those questions: If you have to ask, then use double. If you
don't have to ask, then the answer is quite different.
Nov 15 '05 #12

P: n/a
maadhuu <ma************@yahoo.com> wrote:
hello ,
i would like to know as to why double is more efficient than float .
thanking you,
ranjan.


As people will probably tell you, this has not much to do with C
and more to do with hardware issues. Goto comp.arch and be prepared
to wait a month for a straight answer or until the nuclear war is over.
-----------------------------------------------------------------
New defn for C21/indictment of public education:
"Science and engineering is pretty much the same thing."
Nov 15 '05 #13

P: n/a
maadhuu wrote on 14/09/05 :
i would like to know as to why double is more efficient than float .


Yes.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.
Nov 15 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.