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

Possible compiler bug?

I am not quick to leap to this conclusion, but...

I have a bit of code for doing a color space conversion (RGB to HSB). This
is not a trvial conversion but it isn't that complicated either. It is just
really a 3D coordinate conversion.

It works perfectly well in the IDE. When running the application direcly, it
mainly works, except for a certain narrow band of colors the calculation
goes wrong.

Unfortunately, any attempt to add debug seems to make the problem disappear.
Indeed, even the inclusion of a line of code which has no effect, eg int x =
y; when x is never used again, makes the problem go away.

The only remotely dodgy thing about the code (it is "standard" code, at
least in its C++ form, I didn't write it) is that it compares 2 floats for
equality. To be fair, it first assigns a to b, and then later tests if a==b,
so it should work.

Howevr I wonder if some compiler bug is mistakenly deciding the values
cannot be equal in some cases.

Anyway I changed the logic to use flags and it works. But that diesn't prove
much.

Dom

Stunning fractal photographs
http://www.morello.co.uk/fractal.htm
Nov 16 '05 #1
3 1017
Would be nice if you could post some code.
But the float comparison could be the reason since calculated float values
are sometimes stored into 80 bit registers and sometimes into 64 bit
registers.
And if you assign a flaot that is stored in a 80 bit register to one that is
stored in a 64 bit register you can lose some digits and successive equality
tests will give false even the same value was originally assigned to both of
them.

"anon" <no***@nowhere.spam> schrieb im Newsbeitrag
news:41**********@alt.athenanews.com...
I am not quick to leap to this conclusion, but...

I have a bit of code for doing a color space conversion (RGB to HSB). This
is not a trvial conversion but it isn't that complicated either. It is
just
really a 3D coordinate conversion.

It works perfectly well in the IDE. When running the application direcly,
it
mainly works, except for a certain narrow band of colors the calculation
goes wrong.

Unfortunately, any attempt to add debug seems to make the problem
disappear.
Indeed, even the inclusion of a line of code which has no effect, eg int x
=
y; when x is never used again, makes the problem go away.

The only remotely dodgy thing about the code (it is "standard" code, at
least in its C++ form, I didn't write it) is that it compares 2 floats for
equality. To be fair, it first assigns a to b, and then later tests if
a==b,
so it should work.

Howevr I wonder if some compiler bug is mistakenly deciding the values
cannot be equal in some cases.

Anyway I changed the logic to use flags and it works. But that diesn't
prove
much.

Dom

Stunning fractal photographs
http://www.morello.co.uk/fractal.htm

Nov 16 '05 #2
If I could find a small bit of code which showed the problem I would post
it - but even tiny changes to the code seem to alter the situation so I am
doubtful of the chances of finding a small example. The problem is in the
middle of a large library.

What you are saying seems to make sense (at least, yet another straw to
clutch at :) Do you know how the compiler would choose which type of float
to use? Why would it be different for the IDE?

Would it help to use doubles? Your theory would explain why my alternative
flag implementation works, at least.

Dom

"cody" <de********@gmx.de> wrote in message
news:#7**************@tk2msftngp13.phx.gbl...
Would be nice if you could post some code.
But the float comparison could be the reason since calculated float values
are sometimes stored into 80 bit registers and sometimes into 64 bit
registers.
And if you assign a flaot that is stored in a 80 bit register to one that is stored in a 64 bit register you can lose some digits and successive equality tests will give false even the same value was originally assigned to both of them.

"anon" <no***@nowhere.spam> schrieb im Newsbeitrag
news:41**********@alt.athenanews.com...
I am not quick to leap to this conclusion, but...

I have a bit of code for doing a color space conversion (RGB to HSB). This is not a trvial conversion but it isn't that complicated either. It is
just
really a 3D coordinate conversion.

It works perfectly well in the IDE. When running the application direcly, it
mainly works, except for a certain narrow band of colors the calculation
goes wrong.

Unfortunately, any attempt to add debug seems to make the problem
disappear.
Indeed, even the inclusion of a line of code which has no effect, eg int x =
y; when x is never used again, makes the problem go away.

The only remotely dodgy thing about the code (it is "standard" code, at
least in its C++ form, I didn't write it) is that it compares 2 floats for equality. To be fair, it first assigns a to b, and then later tests if
a==b,
so it should work.

Howevr I wonder if some compiler bug is mistakenly deciding the values
cannot be equal in some cases.

Anyway I changed the logic to use flags and it works. But that diesn't
prove
much.

Dom

Stunning fractal photographs
http://www.morello.co.uk/fractal.htm


Nov 16 '05 #3
[Removed invalid group microsoft.public.dotnet.csharp.general]

anon <no***@nowhere.spam> wrote:
I am not quick to leap to this conclusion, but...

I have a bit of code for doing a color space conversion (RGB to HSB). This
is not a trvial conversion but it isn't that complicated either. It is just
really a 3D coordinate conversion.

It works perfectly well in the IDE. When running the application direcly, it
mainly works, except for a certain narrow band of colors the calculation
goes wrong.

Unfortunately, any attempt to add debug seems to make the problem disappear.
Indeed, even the inclusion of a line of code which has no effect, eg int x =
y; when x is never used again, makes the problem go away.

The only remotely dodgy thing about the code (it is "standard" code, at
least in its C++ form, I didn't write it) is that it compares 2 floats for
equality. To be fair, it first assigns a to b, and then later tests if a==b,
so it should work.


No - that isn't guaranteed to work. The no-op code you wrote is
probably having an effect on the JIT to force it to use just 64-bit or
32-bit values rather than the 80-bit register values, as cody said.
Here's a sample program which demonstrates the same kind of effect:

using System;

class Test

{

static float member;

static void Main()
{
member = Calc();
float local = Calc();
Console.WriteLine(local==member);
// Console.WriteLine (local);
}

static float Calc()
{
float d1 = 2.82323f;
float d2 = 2.3f;
return d1*d2;
}

}

As written, it prints "False" on my box. Removing the comment makes it
print "True" as the first line.

Using doubles *may* help, but it's not really a guaranteed way of doing
things. I'd suggest defining some range of values as being "effectively
equal" - take the difference between the two values, and see whether or
not it's smaller than either a fixed number, or some proportion of the
original numbers. (So 99 and 100 may not be "close enough" but 9999999
and 10000000 may be.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

11
by: Rob Williscroft | last post by:
I have the following code , part of a trait to detect wether a type has a member operator "Type" (), it works fine with g++ 3.4 (msvc compiles it but it doesn't work for template'd operator T ())...
13
by: Eric | last post by:
I have a template class that instantiates a variable of the template parameter type as follows: template <class T> struct TemplateClass { T t; }; struct TestClass
9
by: Vinodh Kumar P | last post by:
int main() { int aNormalInt = 0; short aShortInt = 0; aShortInt = aNormalInt; // Why I am not getting a warining for possible data lose in MS VC++6.0, even with warning level 4? return 0; } ...
4
by: veereshai | last post by:
i want to copy the functions from my source file into a new file...and convert each function into a new object file by compiling it. now, i want to invoke the function using the object file i have...
2
by: Bret Pehrson | last post by:
I just need to confirm now (after I've spent several days chasing mystery metadata warnings/errors) that this is *NOT* possible: Link a managed C++ static library into a (managed) C# application....
3
by: Chris Calzaretta | last post by:
From: "Chris Calzaretta" <ccalzaretta@hotmail.com> Subject: Re: Is It Possible? Date: Friday, February 04, 2005 11:44 AM Ok i am posting the code I need to create a form from this web service...
24
by: Arne Demmers | last post by:
Hi, As a project of mine I have to do some C programming, which in fact isn't the real problem. The problem it self is that I will have to write some code that is as minimal as possible, and as...
2
by: venkatbo | last post by:
Hi all, I have python2.4 running on ppc-linux 2.6.17. I'm attempting to get a TurboGears 0.9a9 (using CherryPy 2.2.1) based app running on it. During the TG-app startup sequence, it reaches...
1
by: Gerwin | last post by:
Hi, I have been using the interl IPP lib for some time on a microsoft compiler. Now i was wondering if I can switch to a gnu based compiler and still use the IPP. IPP uses .lib files where as...
71
by: Jack | last post by:
I understand that the standard Python distribution is considered the C-Python. Howerver, the current C-Python is really a combination of C and Python implementation. There are about 2000 Python...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
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...

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.