473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

division... strange behaviour i dont understand

can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");

Jul 10 '06 #1
10 1736
cl***@yahoo.de wrote:
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
What's an unsigned float?

--
Ian Collins.
Jul 10 '06 #2

Ian Collins wrote:
cl***@yahoo.de wrote:
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;

What's an unsigned float?

--
Ian Collins.
yes, unsigned float that is not compiling on my compiler.
im damn shure 500 divided by 300 doesnt equal to zero ;-\
ufFactor = ufFactor / uiNumbers;
any way, that's not 500 / 300.

it is 300 / 500. Should lead to 0.6 if ufFactor is float.
and 0 if it is integral.

-- Murali Krishna

Jul 10 '06 #3
On 9 Jul 2006 21:32:18 -0700, cl***@yahoo.de wrote:
>can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");
unsigned float?

Anyway, it seems thta ufFactor (which should have the value 300.0/500)
is converted to int (thus, rounded to 0) before being compared.

Try :

if (ufFactor == 0.0) AfxMessageBox("0");

This is an tricky comparison, as comparison with doubles (and floats)
is subject to lots of problems due to rounding. You should take a look
at this list, siblig list comp.lang.c++.moderated and cousin lists
comp.lang.c and comp.lang.c.moderated about floating point comparisons

Regards,

Zara
Jul 10 '06 #4
cl***@yahoo.de wrote:
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");
Because unsigned float is not a defined type in C++, the ufFactor will
then be automatically converted to unsigned int.

P.S. Any decent compiler should be able to spot the problem and give
some warnings.

Jul 10 '06 #5
wa*******@gmail.com wrote:
cl***@yahoo.de wrote:
>>can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");


Because unsigned float is not a defined type in C++, the ufFactor will
then be automatically converted to unsigned int.
No, it's just plain wrong and should fail to compile.

--
Ian Collins.
Jul 10 '06 #6
Zara wrote:
>
unsigned float?

Anyway, it seems thta ufFactor (which should have the value 300.0/500)
is converted to int (thus, rounded to 0) before being compared.
If ufFactor is really some floating point-type, then 0 would be
converted to a floating-point type, not the other way around.

Try :

if (ufFactor == 0.0) AfxMessageBox("0");

This is an tricky comparison, as comparison with doubles (and floats)
is subject to lots of problems due to rounding.
There's nothing tricky involved in checking whether a value is 0, and
there are no floating-poitn roundoff issues in this code. Most likely,
"unsigned float" was actually "unsigned int".
Jul 10 '06 #7
<cl***@yahoo.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\
No, but 300 divided by 500 is 0 in integer math.
_________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");

Jul 12 '06 #8
Jim Langston wrote:
<cl***@yahoo.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

No, but 300 divided by 500 is 0 in integer math.
>_________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
WTF is "unsigned float"?
>ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 12 '06 #9

"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
Jim Langston wrote:
><cl***@yahoo.dewrote in message
news:11*********************@b28g2000cwb.googlegr oups.com...
>>can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

No, but 300 divided by 500 is 0 in integer math.
>>_________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;

WTF is "unsigned float"?
A syntax error in his code which has already been discussed.
Jul 12 '06 #10
Jim Langston wrote:
"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
>Jim Langston wrote:
>><cl***@yahoo.dewrote in message
news:11*********************@b28g2000cwb.googleg roups.com...
can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\

No, but 300 divided by 500 is 0 in integer math.

_________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;

WTF is "unsigned float"?

A syntax error in his code which has already been discussed.
Ah... Thanks. Sorry to butt in at the middle of the thread.
Jul 12 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sony Antony | last post by:
I have the following simple program in Solaris Forte compiler 5.4 producing the warning. Though it produces the warning, it works fine as expected. This has been compiling fine without any...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
2
by: Vaddina Prakash Rao | last post by:
Hi all .. I describe here a wierd behaviour .. i dont understand why ... This could be very stupid aswell .. so please bear me .. I have been writing a program to accept multiple parameters and...
8
by: Dave Brown | last post by:
Hi all, I'm having trouble understanding which data type to use to get results I expect. using float, decimal, and double I have tried the following, .. float test = 55/60; I always get 0...
1
by: T-Bone | last post by:
Hi there, I 've an .aspx page which uses formsauthentication. The formsauthentication works fine however. When I insert breakpoints in the code which does the actual authentication, for example...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
5
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
2
by: Vadim Tropashko | last post by:
http://vadimtropashko.wordpress.com/why-relational-division-is-so-uncommon/
10
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response...
4
by: michelqa | last post by:
Hi, I use sendMessage to retrieve information from another application. For some obscur reasons, my code work only in a button click event and nowhere else in my application. I mean I get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.