Click here to Skip to main content
15,924,553 members
Home / Discussions / C#
   

C#

 
AnswerRe: Displaying time of Two Countries?? Pin
malharone19-Jan-06 6:21
malharone19-Jan-06 6:21 
AnswerRe: Displaying time of Two Countries?? Pin
Andy Moore19-Jan-06 6:41
Andy Moore19-Jan-06 6:41 
Questionhow create multi Selection reusult Pin
Sasuko19-Jan-06 4:47
Sasuko19-Jan-06 4:47 
AnswerRe: how create multi Selection reusult Pin
Dario Solera19-Jan-06 6:53
Dario Solera19-Jan-06 6:53 
AnswerRe: how create multi Selection reusult Pin
Dave Kreskowiak19-Jan-06 10:23
mveDave Kreskowiak19-Jan-06 10:23 
GeneralRe: how create multi Selection reusult Pin
Sasuko19-Jan-06 13:32
Sasuko19-Jan-06 13:32 
GeneralRe: how create multi Selection reusult Pin
Dave Kreskowiak19-Jan-06 14:53
mveDave Kreskowiak19-Jan-06 14:53 
QuestionSSLStream and Alert Message Pin
elapid19-Jan-06 4:39
elapid19-Jan-06 4:39 
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 

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.