Monday, March 15, 2010

Bertrand Meyer's Blog and what Dr. Meyer and I have in common

http://bertrandmeyer.com/

Wow! What's scary is that on page 681 of Programming in Scala, I came across the following code:

def value_=(w: Double) {
  if(!(v == w || v.isNaN && w.isNaN)) {
    v = w
    publish(ValueChanged(this))
  }
}

The following explanation was given right after: 
Note that the test whether the value has changed is a bit tricky because it involves the value NaN. The Java spec says that NaN is different from every other value, including itself! Therefore, a test whether two values are the same has to treat NaN specially: two values v, w are the same if they are equal with respect to ==, or they are both the value NaN, i.e., v.isNaN and w.isNaN both yield true.
By itself, that would just be one of those things that make you go hmmm ... but, after I finished the book, I took a look in the biobliography and saw Bertrand Meyer's name and decided to Google him. Guess what I found as the first post on his blog? A post titled Reflexivity, and other pillars of civilization, which contains:
 ... Such properties are some of the last ramparts of civilization. If they go away, what else is left? 
 Followed by:

754 enters the picture

Now come floating-point numbers and the famous IEEE “754” floating-point standard [1]. Because not all floating point operations yield a result usable as a floating-point number, the standard introduces a notion of “NaN”, Not a Number; certain operations involving floating-point numbers may yield a NaN. The term NaN does not denote a single value but a set of values, distinguished by their “payloads”.
Yes, Dr. Meyer is pissed about NaN, and he tears NaN a new one using the type of mathematical rigor I last suffered back in MATH 414.

For what it's worth, Thank You, Dr. Meyer, for I too thought think that NaN is stupid.

And I'm left wondering whether Dr. Meyer was reading Programming in Scala, too.

1 comments:

  1. I am very interested in this sphere and reading this post I have known many new things, which I have not known before. Thanks for publishing this great article here.

    ReplyDelete