why is double more efficient than float ?

M

maadhuu

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

Ulrich Eckhardt

maadhuu said:
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
 
A

Alexei A. Frounze

maadhuu said:
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
 
M

Michael Mair

maadhuu said:
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
 
N

Novitas

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.
 
P

Peter Nilsson

Alexei said:
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.
 
S

Simon Morgan

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.
 
M

Michael Mair

Simon said:
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
 
C

Christian Bau

Michael Mair said:
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.
 
R

russell kym horsell

maadhuu said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top