# Board index » cppbuilder » if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

## if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

2005-05-26 02:46:58 AM
cppbuilder70
Have Borland C++ builder ver. 5.02. float ft and short int total. if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) does not! Why? Checked the the variables out and ft = 1, total = 1 yet the 'if statement is not executed'. With 2 it works fine. Weird... Please reply directly. Remove one 's' from email.

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

##### Quote
Have Borland C++ builder ver. 5.02. float ft and short int total. if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) does not! Why? Checked the the variables out and ft = 1, total = 1 yet the 'if statement is not executed'. With 2 it works fine. Weird... Please reply directly. Remove one 's' from email.
A) This is not an IDE question; you're posting in the wrong newsgroup
enable "line wrapping". Nobody wants to see one huge line of
question.
C) It's considered rude to ask for direct replies. If you're too busy
busy to bother to try answering them.
D) You may consider that floating point arithmetic is not dealing with
exact values, but approximations. When you multiply or divide by
2, you essentially "shift" the value in the bits, thereby not
corrupting the bit patterns. When you multiply by 10, it can
result in values that are not perfectly representable in floating
point notation. Using operator== to compare values is almost
always wrong. Also, converting floats to integral values is also
error prone, since 1 may be actually 0.9999999998, and when you
perform the conversion, it does NOT round, it simply drops the
fractional part. Thus, 0.9999999999 converts to int(0), not
int(1).
E) This is a classic problem. There are tons of articles on it.
--
Chris (TeamB);

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

On 25 May 2005 11:46:58 -0700, JAVABAD wrote:
##### Quote
Have Borland C++ builder ver. 5.02. float ft and short int total. if
((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) does not! Why?
Checked the the variables out and ft = 1, total = 1 yet the 'if
statement is not executed'. With 2 it works fine. Weird... Please reply
directly. Remove one 's' from email.
If you don't have time to read the newsgroup. we don't have time to reply.
Meanwhile check this on floating point arithmetic:
docs.sun.com/source/806-3568/ncg_goldberg.html
--
Good luck,
liz

{smallsort}

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

Sorry for posting in the wrong area and the no line wrap
is not my fault. Posting via a html page does not have line
wrap that I know of. As far as asking for a reply directly
I did not state what kind of a reply. Like 'check groups'.
News groups answers can sometimes take weeks! So what you
are saying is that 2/2 = .9999999 as a float and when printed
out to screen as a float its 1 eactly? I compiled a program
on Borland 4.52 perfectly and it ran perfectly. Now I try to
compile on 5.02 and it does not? You know I am trying to
learn this c/c++ stuff an it is a real PAIN!!! Give me
assembler any day. C/C++ compilers are very weird beasts...
Its no wonder so many programs are buggy.
Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
##### Quote

>Have Borland C++ builder ver. 5.02. float ft and short int total. if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) does not! Why? Checked the the variables out and ft = 1, total = 1 yet the 'if statement is not executed'. With 2 it works fine. Weird... Please reply directly. Remove one 's' from email.

A) This is not an IDE question; you're posting in the wrong newsgroup

enable "line wrapping". Nobody wants to see one huge line of
question.

C) It's considered rude to ask for direct replies. If you're too busy
busy to bother to try answering them.

D) You may consider that floating point arithmetic is not dealing with
exact values, but approximations. When you multiply or divide by
2, you essentially "shift" the value in the bits, thereby not
corrupting the bit patterns. When you multiply by 10, it can
result in values that are not perfectly representable in floating
point notation. Using operator== to compare values is almost
always wrong. Also, converting floats to integral values is also
error prone, since 1 may be actually 0.9999999998, and when you
perform the conversion, it does NOT round, it simply drops the
fractional part. Thus, 0.9999999999 converts to int(0), not
int(1).

E) This is a classic problem. There are tons of articles on it.

--
Chris (TeamB);

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

##### Quote
So what you
are saying is that 2/2 = .9999999 as a float and when printed
out to screen as a float its 1 eactly?
Not really. The IEEE floating point format represents powers of 2
exactly, since they are bits in the binary representation. But powers
of 10 (for example) cannot in general be represented exactly. The
double type is much better than float in this regard. I rarley use
float myself.
##### Quote
I compiled a program
on Borland 4.52 perfectly and it ran perfectly. Now I try to
compile on 5.02 and it does not?
It's more that your expectations are a bit incorrect. When values are
output they are usually rounded so what you see is not what is
internally stored. When you use == the binary representations are
compared directly. The typical solution is to use an epsilon to decide
when two floating point numbers are close enough.
##### Quote
You know I am trying to
learn this c/c++ stuff an it is a real PAIN!!! Give me
assembler any day.
You can have it! :^)
##### Quote
C/C++ compilers are very weird beasts...
Agreed. :^)
##### Quote
Its no wonder so many programs are buggy.
No comment.
--
Bruce

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

Chris Uzdavinis (TeamB) wrote:
##### Quote
C) It's considered rude to ask for direct replies. If you're too busy
we're too busy to bother to try answering them.
Actaully this is a age old USENET tradition to also CC replies.
Apparently it's against the rules here, but I see nothing wrong with
wanting replies also emailed to you. Do you not think one can get too
busy to check groups all the time? Not everyone has the free time ot
spend, especially when you're on the go a lot, such as traveling, and
www.)
I just think it's a little unreasonable to plain outlaw email replies,
at least as a CC to a group reply.
I mean no offense nor disrespect, just my honest opinion.

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

"Segal" < XXXX@XXXXX.COM >writes:
##### Quote
Chris Uzdavinis (TeamB) wrote:

>C) It's considered rude to ask for direct replies. If you're too busy
>we're too busy to bother to try answering them.

Actaully this is a age old USENET tradition to also CC replies.
Apparently it's against the rules here, but I see nothing wrong with
wanting replies also emailed to you.
There's nothing wrong with "wanting" it, but it generally doesn't
happen, at least not here.
##### Quote
Do you not think one can get too busy to check groups all the time?
Sure, but again, why should other trouble to answer if the poster is
##### Quote
Not everyone has the free time ot spend, especially when you're on
the go a lot, such as traveling, and may not even have access to
Borland has had a web interface for their newsgroups for years.
##### Quote
I just think it's a little unreasonable to plain outlaw email replies,
at least as a CC to a group reply.
Another problem is that further discussion tends to be offline, and
then others who may be reading the post on the newsgroup miss out
on those subsequent messages. Many people who take time to answer
here only do so knowing that more than one person benefits. If I were
to CC you an email response, for example, then most likely that's how
you'd see the post, and if you replied, it'd only go to me. Everyone
else would not see your question, and in order for me to answer, I
would have to go out of my way to post your question then my answer.
(And I'd rather not have to trouble with doing that.)
There is also the problem of personal email answers being considered
"consulting", which usually is not a free service.
##### Quote
I mean no offense nor disrespect, just my honest opinion.
None taken. I didn't write the policy... :)
--
Chris (TeamB);

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

Chris Uzdavinis (TeamB) wrote:
##### Quote
"Segal" < XXXX@XXXXX.COM >writes:

>Chris Uzdavinis (TeamB) wrote:
>
>>C) It's considered rude to ask for direct replies. If you're too
>>then we're too busy to bother to try answering them.
>
>Actaully this is a age old USENET tradition to also CC replies.
>Apparently it's against the rules here, but I see nothing wrong with
>wanting replies also emailed to you.

There's nothing wrong with "wanting" it, but it generally doesn't
happen, at least not here.
No offense, but thats just an assumption. Few people say it, but if
you're really busy a lot of the time (ie, traveling, such as for
business, sometimes only having email-only temp connection, having an
emailed copy can be a blessing. I speak from personal experience.)
##### Quote
>Do you not think one can get too busy to check groups all the time?

Sure, but again, why should other trouble to answer if the poster is
Again, it is possible that later the poster will nto have web or ng
access, as when you're on the road, some places (like in public internet
booths, or at convention centers, etc) you could be i na sition where
you ONLY have email access.
##### Quote
>Not everyone has the free time ot spend, especially when you're on
>the go a lot, such as traveling, and may not even have access to

Borland has had a web interface for their newsgroups for years.
Which is only good if you have acess to it.
##### Quote
>I just think it's a little unreasonable to plain outlaw email
>replies, at least as a CC to a group reply.

Another problem is that further discussion tends to be offline, and
then others who may be reading the post on the newsgroup miss out
on those subsequent messages. Many people who take time to answer
here only do so knowing that more than one person benefits.
Well the reply can be BOTH posted and cc'ed, so the replies to the OP
are seens. It, however, has always been the responsibility (and choice)
of a poster if they want to reply back to the group eventrually. Again,
posting in the group may not even be possible later, hence the reason
one might ask for a CC'ed copy.
##### Quote
If I were
to CC you an email response, for example, then most likely that's how
you'd see the post, and if you replied, it'd only go to me. Everyone
else would not see your question, and in order for me to answer, I
would have to go out of my way to post your question then my answer.
(And I'd rather not have to trouble with doing that.)
That is up to the OP if they want to also post what they repleid back,
in the group; they can always post it when they get the chance.
##### Quote
There is also the problem of personal email answers being considered
"consulting", which usually is not a free service.

>I mean no offense nor disrespect, just my honest opinion.

None taken. I didn't write the policy... :)
Well, I don't see how its even possible to outlaw CC'ing a post, but in
try to do so apparently, thye are blatently ignoring 2 decades of
established USENET tradition. This many not be USENET, but these groups
*are* visible from most usenet servers, and some even let you post from
their servers.
Bottom line, ther shoudl NEVER been any regulation on CC'ing a post. It
has always been an accepted alternate method. In fact CC'ing a post was
long considered common courtesy in most public ng realms. It may not
always be possible for one to check the ng again later, and trying to
forbid simply asking for an emailed copy of a reply to the original
poster, where the replyer can even ask that replies be directed to
usenet and not themselves, is rather short sighted in my most humblest
opinion.

## Re:if ((ft/2) == (total/2)) works, if ((ft/10) == (total/10)) NO!

"Segal" < XXXX@XXXXX.COM >writes:
##### Quote
Well, I don't see how its even possible to outlaw CC'ing a post, but in
Nobody said it's "outlawed" to do. On Borland's servers, requesting
that answers be emailed is discouraged.
##### Quote
try to do so apparently, thye are blatently ignoring 2 decades of