Click here to Skip to main content
15,895,709 members
Home / Discussions / C#
   

C#

 
AnswerRe: SSLStream and Alert Message Pin
elapid19-Jan-06 8:28
elapid19-Jan-06 8:28 
GeneralRe: SSLStream and Alert Message Pin
Dave Kreskowiak19-Jan-06 10:05
mveDave Kreskowiak19-Jan-06 10:05 
AnswerRe: SSLStream and Alert Message Pin
Dave Kreskowiak19-Jan-06 10:02
mveDave Kreskowiak19-Jan-06 10:02 
GeneralRe: SSLStream and Alert Message Pin
elapid19-Jan-06 10:50
elapid19-Jan-06 10:50 
GeneralRe: SSLStream and Alert Message Pin
Dave Kreskowiak19-Jan-06 11:54
mveDave Kreskowiak19-Jan-06 11:54 
GeneralRe: SSLStream and Alert Message Pin
elapid19-Jan-06 12:54
elapid19-Jan-06 12:54 
QuestionHow to do media streaming? Pin
Divyang Mithaiwala19-Jan-06 4:13
Divyang Mithaiwala19-Jan-06 4:13 
QuestionFloating point compare Pin
_eulogy_19-Jan-06 3:59
_eulogy_19-Jan-06 3:59 
Hi!
I'm working on some math routines, and I need to see if two double's are *almost* equal. I've read

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

and tried to implement the same thing in C# with doubles. After a bit of fiddling I got this following code:
public static bool CheckedApproximatelyEqual(double a, double b, int maxSteps)
{
	if (double.IsInfinity(a) || double.IsInfinity(b))
		return false;

	if (double.IsNaN(a) || double.IsNaN(b))
		return false;

	ulong aInt = unchecked((ulong)BitConverter.DoubleToInt64Bits(a));
	if ((aInt & 0x8000000000000000) == 0x8000000000000000) aInt = 0x8000000000000000 - aInt;

	ulong bInt = unchecked((ulong)BitConverter.DoubleToInt64Bits(b));
	if ((bInt & 0x8000000000000000) == 0x8000000000000000) bInt = 0x8000000000000000 - bInt;

	long dif = unchecked(Math.Abs((long)aInt - (long)bInt));

	return dif <= maxSteps;
}

Now the question is how does this look? Do you have any methods you believe are better for comparing floats?

There's *AT LEAST* one problem with this implementation, and that is denormalized values. Any suggestions on how to handle them? I guess I can just round them off to either zero or the smallest normalized value depending on their value!?
QuestionFetch variable information over multiple lines with regex Pin
SirErugor19-Jan-06 3:42
SirErugor19-Jan-06 3:42 
QuestionRemove white space from the beginning of a rich text Pin
Agyeman19-Jan-06 3:30
Agyeman19-Jan-06 3:30 
AnswerRe: Remove white space from the beginning of a rich text Pin
CWIZO19-Jan-06 3:39
CWIZO19-Jan-06 3:39 
GeneralRe: Remove white space from the beginning of a rich text Pin
Agyeman19-Jan-06 3:44
Agyeman19-Jan-06 3:44 
AnswerRe: Remove white space from the beginning of a rich text Pin
CWIZO19-Jan-06 3:47
CWIZO19-Jan-06 3:47 
GeneralRe: Remove white space from the beginning of a rich text Pin
Agyeman19-Jan-06 6:01
Agyeman19-Jan-06 6:01 
QuestionLibraries of functions Pin
Roger Jane19-Jan-06 3:27
Roger Jane19-Jan-06 3:27 
AnswerRe: Libraries of functions Pin
CWIZO19-Jan-06 3:42
CWIZO19-Jan-06 3:42 
AnswerRe: Libraries of functions Pin
Werdna19-Jan-06 4:43
Werdna19-Jan-06 4:43 
GeneralRe: Libraries of functions Pin
Roger Jane20-Jan-06 7:14
Roger Jane20-Jan-06 7:14 
QuestionBinding Datagrid to a bidimensional array Pin
hellamasta19-Jan-06 3:21
hellamasta19-Jan-06 3:21 
Questionfor RealCondor Pin
Sasuko19-Jan-06 3:13
Sasuko19-Jan-06 3:13 
AnswerRe: for RealCondor Pin
Colin Angus Mackay19-Jan-06 4:16
Colin Angus Mackay19-Jan-06 4:16 
QuestionNetwork problem Pin
snouto19-Jan-06 3:10
snouto19-Jan-06 3:10 
AnswerRe: Network problem Pin
c#guy381119-Jan-06 6:27
c#guy381119-Jan-06 6:27 
AnswerRe: Network problem Pin
mcljava19-Jan-06 10:35
mcljava19-Jan-06 10:35 
GeneralRe: Network problem Pin
snouto19-Jan-06 10:48
snouto19-Jan-06 10:48 

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.