🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Floating point equal to Integer Value ?

#68
From: Sanjay kumar
Date: Wed, 11 Jul 2001 07:37
36 lines
2451 bytes
Hi I think it would be no problem if you convert float to integer
instead of interger to float just for comparision purpose

instead of (float(x) == y) 
to (x == (int) y)

this will never fail.

Sanjay 

"Alya Al Omrani" <alomrani@emirates.net.ae> wrote in message news:<9iejot$4an2@news.emirates.net.ae>...
> 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
Technical Details
Message-ID: <9cb96ed6.0107102337.c746ba9@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!postnews1.google.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: 108b44,dbd8a1f951d6b446
X-Google-Attributes: gid108b44,public
X-Google-Thread: 108717,dbd8a1f951d6b446
X-Google-Attributes: gid108717,public
X-Google-Thread: 10d4ba,dbd8a1f951d6b446
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 114592,dbd8a1f951d6b446
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,dbd8a1f951d6b446
X-Google-Attributes: gid109fba,public
X-Google-Thread: 10b1c0,dbd8a1f951d6b446
X-Google-Attributes: gid10b1c0,public
X-Google-ArrivalTime: 2001-07-11 00:37:32 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mail
From: san_2820@yahoo.com (Sanjay kumar)
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: 11 Jul 2001 00:37:31 -0700
Organization: http://groups.google.com/
Lines: 36
Message-ID: <9cb96ed6.0107102337.c746ba9@posting.google.com>
References: <9iejot$4an2@news.emirates.net.ae>
NNTP-Posting-Host: 203.122.21.51
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 994837052 21814 127.0.0.1 (11 Jul 2001 07:37:32 GMT)
X-Complaints-To: groups-support@google.com
NNTP-Posting-Date: 11 Jul 2001 07:37:32 GMT