473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

why is double more efficient than float ?

hello ,
i would like to know as to why double is more efficient than float .
thanking you,
ranjan.

Nov 15 '05 #1
13 3309
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
"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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
Hello all, I would like to solicit suggestions on how to most efficiently accomplish something. I have profiled the project I'm working on and have found that calls to fabs() are taking a very...
5
by: da Vinci | last post by:
Hi Gents, This is what I am trying to do. Say you have a double or a float with the value 14.5624 for example. How could I take that variable and get the 14 into an integer variable and the...
4
by: Michael Mair | last post by:
Hi there, actually, I have posted the same question in g.g.help. As there were no answers, I am still not sure whether this is a bug or only something open to the compiler that is seemingly...
9
by: Sisyphus | last post by:
Hi, I have some software that does the following (in an attempt to determine whether the double x, can be represented just as accurately by a float): void test_it(double x) { float y = x;...
44
by: Daniel | last post by:
I am grappling with the idea of double.Epsilon. I have written the following test: public void FuzzyDivisionTest() { double a = 0.33333d; double b = 1d / 3d; Assert.IsFalse(a == b,...
8
by: Lionel | last post by:
Hi all, I'm facing a strang issue doing calculation on Double values. I read some thread on the newsgroups warning about type translations (eg Single to Double), but here I'm doing no conversion...
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
60
by: Erick-> | last post by:
hi all... I've readed some lines about the difference between float and double data types... but, in the real world, which is the best? when should we use float or double?? thanks Erick
4
by: siryuhan | last post by:
I am trying to apply bitwise operations on float, double, and long double values. I do not believe this is possible natively, so I created a wrapper class to construct a double value given two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.