473,405 Members | 2,334 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,405 software developers and data experts.

Strange float behaviour

I have a problem with a program i have that only shows when the code is
compiled in "Release" mode and ONLY when the .NET debugger is not
attached to the process.

I have some drawing code that checks to see if a data point is inside
the bounding rectangle of a graph. if it is not then the point is not
shown.

I find that in the deployed code the final data point does not show. I
therefore went through the code adding message boxes to see if i could
spot any problems.

I eventually did something like this

Dim graphRectangle as RectangleF
graphRectangle = graph.GridRect

MessageBox.Show(graph.GridRect.Right = graphRectangle.Right).ToString)
MessageBox.Show(graph.GridRect.Right - graphRectangle.Right).ToString)

MessageBox.Show((graph.GridRect.Right = CType(graphRectangle.Right,
Single)).ToString())

MessageBox.Show(BitConverter.ToInt32(BitConverter. GetBytes(graph.GridRect.Right),
0).ToString)

MessageBox.Show(BitConverter.ToInt32(BitConverter. GetBytes(graphRectangle.Right),
0).ToString)

now you would expect the graphRectangle variable to be the same as the
graph.GridRect property but it is not.

The first message box returns false
The second message box shows 2.098..E-05
The third and fourth message boxes show 11443800 indicating that the
binary values are the same.

So what is happening!! I have found using ctype to convert the value
to a single on each side of the equals operator yields the correct
value. I also found it completly impossible to reporduce this problem
outside my project.

Any ideas anyone??

VB.NET on .NET 1.1 sp1

Aug 25 '06 #1
1 1102
<te*********@yahoo.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
>
now you would expect the graphRectangle variable to be the same as the
graph.GridRect property but it is not.

The first message box returns false
The second message box shows 2.098..E-05
The third and fourth message boxes show 11443800 indicating that the
binary values are the same.

So what is happening!! I have found using ctype to convert the value
to a single on each side of the equals operator yields the correct
value. I also found it completly impossible to reporduce this problem
outside my project.

Any ideas anyone??

VB.NET on .NET 1.1 sp1
Just a visitor around here.... If floats are causing you greif, here's some
good info.

What Every Computer Scientist Should Know About Floating-Point Arithmetic
http://docs.sun.com/source/806-3568/ncg_goldberg.html

(Complete) Tutorial to Understand IEEE Floating-Point Errors
http://support.microsoft.com/kb/42980/en-us

FP Representation
http://www.cprogramming.com/tutorial...sentation.html

fwiw, do a web search on comparing numbers to EPSILON instead of each
other... for example,

If X = Y Then
Do Something
End If

can be replaced by

If Abs(X - Y) < EPSILON Then
Do Something
End If

fwiw, you can find the value for EPSILON in the C header files that ship
with VS... or, just figure out the minimum resolution you need and create
your own EPSILON_LIKE constant.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Aug 25 '06 #2

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

Similar topics

0
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
4
by: Tomasz Lisowski | last post by:
Hi, We are distributing our Python application as the short main script (.py file) and a set of modules compiled to the .pyc files. So far, we have always treated .pyc files as portable between...
5
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/BeallSprings/WC.Deed%20GG.116-17.html using the CSS at http://pages.prodigy.net/chris_beall/BeallSprings/BSstyle.css The page is a transcript of a...
12
by: unique | last post by:
I have written some programs in c lang yet but today I get confused with output i get. I have function educate(..) which i call in main program this way: J = educate(no_layers, no_neurons,...
16
by: Enekajmer | last post by:
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 }
31
by: gamehack | last post by:
Hi all, I've been testing out a small function and surprisingly it does not work okay. Here's the full code listing: #include "stdlib.h" #include "stdio.h" char* escaped_byte_cstr_ref(char...
10
by: clqrq | last post by:
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...
8
by: siddharth.munshi | last post by:
union something { float a; int b; } u; int main() { printf("%d %d\n",&u.a,&u.b); u.a = 200;
0
by: vytas | last post by:
hi, I've just ran into very strange IE behaviour. I have a table with some content: <table width="200" border="1"> <tr> <td width="50%"> <div class="bord" style="float:...
29
by: candy_init | last post by:
Hi all, I just came across the following program: #include <stdio.h> int main() { float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); return 0;
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.