1

I've got a function which is returning a Float.(average) Then I get that output and compare it within another function

      | average == 0 = "0"
      | average >= 0 = (show average)

But when the average is NaN I can't do this comparing cause NaN seems to be /=0. How can I compare a NaN value?

Bobys
  • 677
  • 1
  • 14
  • 37
  • 6
    See [`isNaN`](http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:isNaN) – Thomas M. DuBuisson Feb 28 '14 at 01:24
  • @ThomasM.DuBuisson Want to copy paste those two words as an answer? The lure of internet points + this question can be marked answered/closed – daniel gratzer Feb 28 '14 at 04:56
  • 1
    BTW, the parens are superfluent. Just write `= show average`. (I would recommend to add a bit of space before the `=`, though, to better seperate the guard condition from the target result.) – leftaroundabout Feb 28 '14 at 10:14
  • Yep, isNaN is what you're looking for. Additionally, maybe you could use an `otherwise` guard after the above two. NaN and 0 will generate False with every relational operator. – Tim Feb 28 '14 at 17:54

1 Answers1

2

You can use the isNaN function which is part of the RealFloat class.

John F. Miller
  • 26,961
  • 10
  • 71
  • 121