Re: Re: Initialization and Floating Problem.

Alain Gurrea <[email protected]>
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
Kedar,

The difference in behavior of ANSI C floating point
constants and traditional C floating point constants
can cause numerical and perfomance differences in Code
ported from traditional C to ANSI C compiler.

Consider the following example:

#define PI 3.1415926
float a, b;

b = a * PI;

The result type of b depends on which compilation
options you use.

Table 2.1 Shows effect of compilation options on
floating point conversions.

Compilation   PI Constant Type    Behavior
Option
-cckr        double             (float)((double)a*PI)
-cckr -float float              a * PI
-xansi       double             (float)((double)a*PI)
-ansi        double             (float)((double)a*PI)

Each conversion incurs computational overhead.

The -float flag has no effect if you also specify
-ansi or -xansi. To prevent the promotion of floating
constants to double(and promoting the computation to a
double precision multiply) you must specify the
constant as a single precision floating point
constant. In the previous example, you would use the
following statement.

#define PI 3.1415926F   /* Single Precision float */

Traditional C(compiled with the -cckr option) does
noot recognized the float qualifier, f, however,
instead, write the constant definition as follows:

#ifdef __STDC__
#define PI 3.1415926f
#else
#define PI 3.1415926
#endif

-alain
JairoSoft Team


--- kedarpathikonda <[email protected]> wrote:

> 2.
> > float c=0.7;
> > if(c<0.7)
> > printf("yes");
> > else
> > printf("no");
> >
> > output:-yes
> > if i write c<0.7f then it
> > prints no.
> > i would like to know the reason
> > behind this i.e
> > what's happening internally.
> 
> 
> 
> the reason is because if give if(c<0.7) it will take
> 0.7 as double by 
> default
> 
> 
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.