472,958 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1716
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.