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.