473,394 Members | 1,869 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,394 software developers and data experts.

Extremely wierd problem I just cannot explain...works in debug, does not work in release.

In the following section of code:

if(addr == address)
{
this.cache.Add(entry);
return entry.Name;
}

Looks pretty easy and simple. Problem though is, the return entry.Name
line is only sporadically executed even though it is impossible for an
address match to not occur since I know for a fact the necessary data
is there for it to occur.

What happens instead, the function executes the exception at the end
that happens if it never found an address match.

This ONLY happens in Release mode though!
In Debug mode, everything runs just fine...

To make things wierder, the following code works fine in release mode:

if(addr == address)
{
string a = addr.ToString();
string b = address.ToString();
b = a + b;
if (b == "testing234")
{
MessageBox.Show("blah");
}

this.cache.Add(entry);
return entry.Name;
}

Yes, I know it looks stupid. I know it doesn't make sense (at least to
me). But if I add that totally nonesense string code with the if
statement to make sure the compiler doesn't optimize it out, then the
return line is run everytime.

If someone wants to look at the whole function in its entirety, it is
available at http://www.somrek.net/function.cs

I've never seen anything like this happen before and I don't know if I
actually found some issue or if I am just being braindead. =)

Any ideas or thoughts would be much appreciated!

Thanks,

Stephan
Nov 6 '06 #1
4 1495
>If someone wants to look at the whole function in its entirety, it is
available at http://www.somrek.net/function.cs
Looks like my web server doesn't like me putting up .cs files...

So I changed it to http://www.somrek.net/function.txt

Nov 6 '06 #2
float address = entry.Address;
address += (float)entry.Bit/10.0f;
if(addr == address)The thing that catches my eye is that you are testing
equality on floating point values. That is generally a big no no as
floating point values are typically NOT exact.

If you had a "logical" value of 10.0, it might actually come out to
10.0000000001 or somethign along that line. Thus the test for equality
would fail. The better way would be to substract the two and take the
Math.Abs() - see if that value is less than a certain 'tolerance' level
(aka: they are close enough that you know they are actually the same).

--
Adam Clauss

"Stephan Rose" <ke*******************@no.somrek.spam.netwrote in message
news:eh********************************@4ax.com...
>
>>If someone wants to look at the whole function in its entirety, it is
available at http://www.somrek.net/function.cs

Looks like my web server doesn't like me putting up .cs files...

So I changed it to http://www.somrek.net/function.txt

Nov 6 '06 #3
I agree with Adam: comparing floats / doubles for equality is a big
no-no.

Furthermore, a float or double should be used to store _only_ measured
quantities for which the concept of error makes sense. For example, you
could use a float or double to store "35.1523mm of rain", because if
you you're going to compare that quantity to something else, a
statement like "within 0.00001mm of yesterday's rainfall" makes sense.

You should never use floats or doubles to represent quantities or
things where precise values matter. The classic example is using them
to store monetary values (a quick road to losing / gaining pennies here
and there). So, I have to wonder exactly what "address" is... I have
the sneaking suspicion that losing a digit on an "address" would be
disastrous....

In cases in which your application can't tolerate precision loss you
should use decimal. If the number of decimal places is fixed then you
may also be able to use int or long and just remember how many decimal
places there are.

Adam Clauss wrote:
float address = entry.Address;
address += (float)entry.Bit/10.0f;
if(addr == address)The thing that catches my eye is that you are testing
equality on floating point values. That is generally a big no no as
floating point values are typically NOT exact.

If you had a "logical" value of 10.0, it might actually come out to
10.0000000001 or somethign along that line. Thus the test for equality
would fail. The better way would be to substract the two and take the
Math.Abs() - see if that value is less than a certain 'tolerance' level
(aka: they are close enough that you know they are actually the same).

--
Adam Clauss

"Stephan Rose" <ke*******************@no.somrek.spam.netwrote in message
news:eh********************************@4ax.com...
>If someone wants to look at the whole function in its entirety, it is
available at http://www.somrek.net/function.cs
Looks like my web server doesn't like me putting up .cs files...

So I changed it to http://www.somrek.net/function.txt
Nov 6 '06 #4
On 6 Nov 2006 09:21:50 -0800, "Bruce Wood" <br*******@canada.com>
wrote:
>I agree with Adam: comparing floats / doubles for equality is a big
no-no.

Furthermore, a float or double should be used to store _only_ measured
quantities for which the concept of error makes sense. For example, you
could use a float or double to store "35.1523mm of rain", because if
you you're going to compare that quantity to something else, a
statement like "within 0.00001mm of yesterday's rainfall" makes sense.

You should never use floats or doubles to represent quantities or
things where precise values matter. The classic example is using them
to store monetary values (a quick road to losing / gaining pennies here
and there). So, I have to wonder exactly what "address" is... I have
the sneaking suspicion that losing a digit on an "address" would be
disastrous....

In cases in which your application can't tolerate precision loss you
should use decimal. If the number of decimal places is fixed then you
may also be able to use int or long and just remember how many decimal
places there are.

Adam Clauss wrote:
>float address = entry.Address;
address += (float)entry.Bit/10.0f;
if(addr == address)The thing that catches my eye is that you are testing
equality on floating point values. That is generally a big no no as
floating point values are typically NOT exact.

If you had a "logical" value of 10.0, it might actually come out to
10.0000000001 or somethign along that line. Thus the test for equality
would fail. The better way would be to substract the two and take the
Math.Abs() - see if that value is less than a certain 'tolerance' level
(aka: they are close enough that you know they are actually the same).
Ya know what guys, I didn't even think about that....

I am definitely going to check that tomorrow!

Thanks for the heads up!

--
Stephan
2003 Yamaha R6

kimi no koto omoidasu hi nante nai no wa
kimi no koto wasureta toki ga nai kara
Nov 6 '06 #5

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

Similar topics

3
by: vool | last post by:
Hi all, I've got a really wierd problem here. When I access a web page that adds information to a database on a PC running XP Pro it works as it should. When I access the same page from a...
6
by: Ariel | last post by:
I have an application that works correctly in debug mode but it does not work in release. I am not using anything of the class system.diagnostics. I tried to disable the optimization code, but...
2
by: CMEDIA_SOUND | last post by:
I have a peculiar problem, I have a tabpage with a label control on it. When i set a background image to the tabpage and drag the label around it has paint issues in that it is slow, granted the...
1
by: Christian Wallukat | last post by:
Hi NG, I have a problem with a component written in VC6.0 SP5. The componnet shares Data over pointer: (PVOID)pData = (PVOID)some data... The debug version works fine... But I have...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
0
by: Mark Goldin | last post by:
Here is a solution from MS Press book that installed into default location "C:\Microsoft Press\ASPNETSBS_CS". Microsoft Visual Studio Solution File, Format Version 8.00...
2
by: Ravi | last post by:
Hi everyone, I've a C# .NET application that works as expected when built in the debug mode. However, it behaves strangely when built in the Release mode. Having the .pdb file included makes...
3
by: jt | last post by:
For some stupid reason, I can't get this to work in Release mode, but works well in Debug mode. Below is the function: Here is the line: pos=strpos(pszCmdLine,cmdLineStr); // in release mode...
3
by: walkeraj | last post by:
I'm trying to compile an open source game called IVAN , and I'm able to compile it from a makefile, but not from an IDE. I have attempted to recreate the way the makefile compiles the project as...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.