Monday, May 05, 2008

Sigh

> (eqv? +NaN.0 +NaN.0)
#t
> (eq? +NaN.0 +NaN.0)
#t
> (= +NaN.0 +NaN.0)
#f
> (equal? +NaN.0 +NaN.0)
#t

8 comments:

Anonymous said...

It's a feature not a bug. IEEE 754 mandates that NAN is not equal to any other number including NAN itself (even if it's the same bit pattern). So if X != X, you know that X is NAN.

Jason Riedy said...

Ok, this takes a bit of thinking and explaining... eqv? makes sense; two NaNs act equivalently w.r.t. typical (arithmetic) operations.

eq? is questionable and may be non-portable. The significand of a NaN may carry a payload, and some hardware systems have rules for how that payload propagates. If your Scheme implementation gives access to those features, two NaNs may be not eq?. If it doesn't, then it makes sense for a system to say two NaNs are eq?.

equal? is determined by eqv?. That may be a poor choice here, but it's standard.

And = tests numeric equality. NaN is "Not a Number", hence not a numeric quantity. Including those in numerical relations is tricky. IEEE-754 also mandates that comparisons involving non-numeric quantities signal and invalid operation condition. Few programming systems provide access to the conditions, and most that do make them nigh impossible to use.

The rationale behind returning #f for = is to allow non-stop execution; you do not want to mandate new control paths. So the operation must return some value. Returning #t leads to many errors in existing, NaN-unaware codes. Returning #f allows codes to check for NaNs even if the programming system doesn't directly support them, so long as the test is not optimized out. So the standard chose #f.

steck said...

All NaNs are equal?, but some are more = than others.

-- Paul

yadongbiz said...

Very good blog post about plastering a one bed flat. I am very happy to see this post and interested to find another good post in coming days. Thanks for it 한국야동

Also do visit may web page check this link 야설

yahanvideonet said...

It was wondering if I could use this write-up on my other website, I will link it back to your website though. Great Thanks 한국야동

Also do visit may web page check this link 야설

koreayadongcom said...

I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site. 야동

Also do visit may web page check this link 국산야동

japanyadongcom said...

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article. 국산야동

Also do visit may web page check this link 한국야동

chinayadongnet said...

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoy every little bit of it and I have you bookmarked to check out new stuff you post. 한국야동

Also do visit may web page check this link 야동