Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:14:40+00:00 2026-05-24T18:14:40+00:00

In my program this fragment: trace.log( String.Format(a= {0:R} b= {1:R} a<b= {2}, b.GetPixel(447, 517).GetBrightness(),

  • 0

In my program this fragment:

  trace.log(
   String.Format("a= {0:R} b= {1:R} a<b= {2}", 
    b.GetPixel(447, 517).GetBrightness(), (100F / 255F),
    b.GetPixel(447, 517).GetBrightness() < (100F / 255F))
  );

outputs this in Debug\prog.exe:

 a= 0.392156869 b= 0.392156869 a<b= False

but this different result in Release\prog.exe:

 a= 0.392156869 b= 0.392156869 a<b= True

Can anyone explain why the same operands give a different comparision result? And recommend a remedy, ideally program-wide such as a compiler switch? Thanks.

EDIT: Clarification: the above results are from launching Debug\prog.exe and Release\prog.exe in Windows Explorer.

EDIT: Further info: executing from VS, “Start Debugging” gives False (i.e. the accurate result, same as WE-launched Debug\prog.exe), and “Start without debugging” gives True (i.e. the inaccurate result, same as WE-launched Release\prog.exe.

EDIT: Alternative test cases having literals substituted

These two cases

  trace.log(
   String.Format("a= {0:R} b= {1:R} a<b= {2}",
    0.392156869F, 0.392156869F, 
    0.392156869F < 0.392156869F)
  );
  trace.log(
   String.Format("a= {0:R} b= {1:R} a<b= {2}",
    0.392156869F, (100F / 255F),
    0.392156869F < (100F / 255F))
  );

show no discrepancy in Debug and Release output. This case:

  trace.log(
   String.Format("a= {0:R} b= {1:R} a<b= {2}",
    b.GetPixel(447, 517).GetBrightness(), 0.392156869F,
    b.GetPixel(447, 517).GetBrightness() < 0.392156869F)
  );

shows the same discrepancy (and inaccuracy in Release) as the original test case.

EDIT: Belated minimal test case demoing the problem

Color c = Color.FromArgb( 255, 100, 100, 100 );
trace.log(
 String.Format("a= {0} b= {1} a<b= {2}",
 c.GetBrightness(), 0.392156869F,
 c.GetBrightness() < 0.392156869F)
);

outputs this correct result in Debug\prog.exe:

 a= 0.392156869 b= 0.392156869 a<b= False

but this incorrect result in Release\prog.exe:

 a= 0.392156869 b= 0.392156869 a<b= True

EDIT: Remedies

1) From Peter’s answer below:

trace.log(
 String.Format("a= {0:R} b= {1:R} a<b= {2}",
  c.GetBrightness(), 0.392156869F, 
  c.GetBrightness().CompareTo(0.392156869F)<0)
);

2) From ChrisJJ, the questioner (UPDATED):

float comp = c.GetBrightness();
trace.log(
 String.Format("a= {0:R} b= {1:R} a<b= {2}", 
 comp, 0.392156869F,
 comp < 0.392156869F)
);

I think this adds to the evidence for a Release-mode compiler bug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:14:40+00:00Added an answer on May 24, 2026 at 6:14 pm

    It’s most likely the result of different floating point rules between debug mode and release mode (see here and here).

    Update:

    Thanks to your new update to the question, I was able to reproduce the problem on my machine (64-bit Windows). This appears to happen only when setting the platform to X86; the X64 and AnyCPU platforms show the correct result in release mode. Probably, when the platform is X86, the common language runtime applies X86 emulation in 64-bit machines and apparently messed up in the comparison operator.

    However, I found a possible workaround: Use CompareTo instead of the “<” and “>” operators, like this:

    c.GetBrightness().CompareTo(0.392156869F)<0
    

    On my machine, this will provide the same correct results in X86 as in X64 and AnyCPU.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my program this fragment: trace.Log( String.Format(a= {0:F10} b= {1:F10} a<b= {2}, b.GetPixel(447, 517).GetBrightness(),
For the following code fragment. /*This program demonstartes how a virtual table pointer *
In this program when I debug, it is showing the nil for fileNameString. I
This is fragment of class in my program (I deleted some not important code).
Ok, first off, I didn't program this page with frames! I'll be getting rid
This program I use has it's own variables to set when you run it,
This program stores pairs in a map, counting the number of times a word
This program reads emails (really just a .txt file structured like an email) and
For this program #include <iostream> using std::cout; struct C { C() { cout <<
Consider this program int main() { float f = 11.22; double d = 44.55;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.