Click here to Skip to main content
15,394,327 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using directive Pin
PIEBALDconsult2-Aug-07 15:12
professionalPIEBALDconsult2-Aug-07 15:12 
QuestionDataGridView Pin
sangramkp31-Jul-07 1:26
Membersangramkp31-Jul-07 1:26 
AnswerRe: DataGridView Pin
Herman<T>.Instance31-Jul-07 2:56
MemberHerman<T>.Instance31-Jul-07 2:56 
QuestionNUnit and relative Paths Pin
User 665831-Jul-07 1:25
MemberUser 665831-Jul-07 1:25 
Questionconvertion from word file into pdf file Pin
adilkazmi31-Jul-07 1:14
Memberadilkazmi31-Jul-07 1:14 
AnswerRe: convertion from word file into pdf file Pin
ekynox31-Jul-07 2:36
Memberekynox31-Jul-07 2:36 
AnswerRe: convertion from word file into pdf file Pin
Not Active31-Jul-07 2:36
mentorNot Active31-Jul-07 2:36 
QuestionStrange behavior of comparison with Double.IsPositiveInfinity [modified] Pin
Stefan Troschuetz31-Jul-07 1:13
MemberStefan Troschuetz31-Jul-07 1:13 
Today, I stumbled on the strangest behavior I've seen so far and unfortunatley I'm not able to find an explaination. Here is the problem:
I'm currently testing a library with random generators. The generators have a function NextDouble that generates a floating point random number within a specified range. The range is computed by subtracting the specified minValue from the specified maxValue. Afterwards the computed range is passed to double.IsPositiveInfinity, so the method can throw an exception if an overflow occured.
Strangely the comparison only works in Debug mode (below code outputs "NextDouble: Infinity"). If I run the same code in Release mode the comparison does not work (below code outputs "NextDouble: Not infinity"). I first thought this might be an issue of code optimization, but even if I turn off the optimization in release mode it doesn't work. To make the whole thing even more strange, the comparison works if the final Console.Out is uncommented.

Does the small console application show the same behavior on your computers? Does someone have an explaination for this strange behavior? By the way, I'm running this with .NET framework 2.0.50727.
static class Program
{
    [STAThread]
    static void Main()
    {
		NextDouble(Double.MinValue, Double.MaxValue);

		Console.ReadLine();
	}

	public static void NextDouble(double minValue, double maxValue)
	{
		double range = maxValue - minValue;

		if (double.IsPositiveInfinity(range))
			Console.Out.WriteLine("NextDouble: Infinity");
		else
			Console.Out.WriteLine("NextDouble: Not infinity");

		//Console.Out.WriteLine("NextDouble: " + range);
	}
}



-- modified at 9:11 Tuesday 31st July, 2007


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

www.troschuetz.de

AnswerRe: Strange behavior of comparison with double.PositiveInfinity Pin
Luc Pattyn31-Jul-07 1:30
sitebuilderLuc Pattyn31-Jul-07 1:30 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Stefan Troschuetz31-Jul-07 2:31
MemberStefan Troschuetz31-Jul-07 2:31 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Luc Pattyn31-Jul-07 2:50
sitebuilderLuc Pattyn31-Jul-07 2:50 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Stefan Troschuetz31-Jul-07 3:11
MemberStefan Troschuetz31-Jul-07 3:11 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Luc Pattyn31-Jul-07 3:36
sitebuilderLuc Pattyn31-Jul-07 3:36 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Stefan Troschuetz31-Jul-07 4:23
MemberStefan Troschuetz31-Jul-07 4:23 
JokeRe: Strange behavior of comparison with double.PositiveInfinity Pin
Luc Pattyn31-Jul-07 4:36
sitebuilderLuc Pattyn31-Jul-07 4:36 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Stefan Troschuetz31-Jul-07 4:41
MemberStefan Troschuetz31-Jul-07 4:41 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
PhilDanger31-Jul-07 4:54
MemberPhilDanger31-Jul-07 4:54 
GeneralRe: Strange behavior of comparison with double.PositiveInfinity Pin
Stefan Troschuetz31-Jul-07 9:06
MemberStefan Troschuetz31-Jul-07 9:06 
QuestionWriting a Type to Binary File Pin
JamesBarnes31-Jul-07 0:56
MemberJamesBarnes31-Jul-07 0:56 
AnswerRe: Writing a Type to Binary File Pin
Luc Pattyn31-Jul-07 1:08
sitebuilderLuc Pattyn31-Jul-07 1:08 
GeneralRe: Writing a Type to Binary File Pin
JamesBarnes31-Jul-07 1:11
MemberJamesBarnes31-Jul-07 1:11 
Questionhow to make sure Socket has connected? Pin
Gavin Roberts31-Jul-07 0:56
MemberGavin Roberts31-Jul-07 0:56 
AnswerRe: how to make sure Socket has connected? Pin
led mike31-Jul-07 4:21
Memberled mike31-Jul-07 4:21 
GeneralRe: how to make sure Socket has connected? Pin
Gavin Roberts31-Jul-07 5:08
MemberGavin Roberts31-Jul-07 5:08 
GeneralRe: how to make sure Socket has connected? Pin
led mike31-Jul-07 5:41
Memberled mike31-Jul-07 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.