Re: Comparission cause problem

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 02/17/05


Date: Thu, 17 Feb 2005 08:30:38 +0000

In article <77c88a3b.0502162127.1009bb68@posting.google.com>, ranjeet
<ranjeet.gupta@gmail.com> writes
> I think I may be missing some points thats why, I have some doubts on the
> above. Please guide me to clear the things in brief. what I am missing.

What you are missing is that most modern processors have floating point
arithmetic units. These are designed to work with a floating point type
that is wider than a float (typically they use an 80-bit type). The
second issue is that in most circumstances the standard conversions are
applied in C and C++ (less so in C++) which promote a float to a double
so if you insist on using a float you may be incurring promotion and
demotion costs as well.

In simple terms the natural floating point type for C and C++ is double
and the natural floating point type for many general purpose CPUs is
either double or something wider than that.

The assumption that float will be faster than double is often false, and
even when it isn't double is generally fast enough.

-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


Relevant Pages

  • Re: libc/printf bug
    ... I don't see that the cast should have any effect at all ... How would you print a float in hex? ... So seems printf gets confused because you present it with a float when i t wants an integer. ... This behavior I have seen in other cases where wrong or missing arguments were presented too. ...
    (comp.os.linux.development.apps)
  • Re: openning a file
    ... 37 float **Allocate2DFloat(int rows, int columns) ... Missing semicolon ';' at the end. ... ReadClassFiletest.c:40: error: syntax error before '{' token ...
    (comp.lang.c)
  • Re: doubles or not
    ... > even a float can not be enough for this, we may need doubles. ... the point that you are missing is "..when integers will do". ... integer math. ...
    (microsoft.public.vc.language)
  • Re: matrix stuff (solving b = A*x) --> using numerical recipes
    ... http://www.library.cornell.edu/nr/bookcpdf/c2-4.pdf p.52-54 AFAIR). ... You are missing ... float b); ... This is not a proper initialization, that is why the compiler complained. ...
    (comp.lang.c)