🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #66

Re: Floating point equal to Integer Value ?

#66
From: Gregory Carvalho
Date: Tue, 10 Jul 2001 20:17
38 lines
2572 bytes
Alya Al Omrani wrote:
> 
> Hi, how can i check if a floating point value is equal to integer value ?
> I tried looking of there is a function that does so but there isn't
> 
> I tried doing the following
> 
> /* lets say those are my values */
> int x=20;
> float x=20.0, z;
> 
> z=(float)x;
> /* I used a printf staetment to check that the value of x was assigned to z
> and it worked ! */
> printf("%f", z);
> 
> /* here i want to check */
> if(z==x)                      /* at this instant it freezes */
>     printf("values are equal");
> else
>     printf("they r not euqal");
> ///////////////
> 
> I sthere a substitue method that i can do so, i tried taking the % modulus
> of both z and x to see if it will give zero but i got same erro, the program
> wont compile

Are you getting an error since you are defining x twice:

> int x=20;
> float x=20.0, z;

You can cast the comparison:

int x=20;
float z=20.0;
...
if(z==(float)x)
Technical Details
Message-ID: <3B4B62D4.FCE579AF@stcinc.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news2.best.com!nntp1.ba.best.com!not-for-mail
References: <9iejot$4an2@news.emirates.net.ae>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,dbd8a1f951d6b446
X-Google-Attributes: gid109fba,public
X-Google-Thread: 10d4ba,dbd8a1f951d6b446
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 108b44,dbd8a1f951d6b446
X-Google-Attributes: gid108b44,public
X-Google-Thread: 114592,dbd8a1f951d6b446
X-Google-Attributes: gid114592,public
X-Google-Thread: 10b1c0,dbd8a1f951d6b446
X-Google-Attributes: gid10b1c0,public
X-Google-Thread: 108717,dbd8a1f951d6b446
X-Google-Attributes: gid108717,public
X-Google-ArrivalTime: 2001-07-10 13:04:48 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news2.best.com!nntp1.ba.best.com!not-for-mail
From: Gregory Carvalho <GregoryC@stcinc.com>
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++,comp.programming,comp.sys.lang.c++,csugrad.programming.c
Subject: Re: Floating point equal to Integer Value ?
Date: Tue, 10 Jul 2001 13:17:24 -0700
Organization: Simplified Technology Company
Lines: 38
Message-ID: <3B4B62D4.FCE579AF@stcinc.com>
References: <9iejot$4an2@news.emirates.net.ae>
Reply-To: GregoryC@stcinc.com
NNTP-Posting-Host: 207.20.238.29
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: nntp1.ba.best.com 994795479 8595 207.20.238.29 (10 Jul 2001 20:04:39 GMT)
X-Complaints-To: abuse@best.com
NNTP-Posting-Date: Tue, 10 Jul 2001 20:04:39 +0000 (UTC)
X-Mailer: Mozilla 4.51 [en] (X11; I; FreeBSD 3.2-RELEASE i386)
X-Accept-Language: en