title: Which is better for testing for non finite floats IsNaN or IsInf?
body: <p>I need to test for non finite floats and eliminate them. I was planing to use  <code>math.IsInf()</code>  to test the floats but I have seen some ppl using  <code>math.IsNaN()</code>  for this purpose. Is one of these better for this purpose than the other ? and if so why?</p>
  
  <p>edit: This has been put on hold because it is unclear so here is more information that will hopefully clarify the question. I was doing exercise 3.1 from "The Go Programming Language" which references this <a href="https://github.com/adonovan/gopl.io/blob/master/ch3/surface/main.go" rel="noreferrer">program</a>. The exercise it asks</p>
  
  <blockquote>
    <p>If the function f returns a non-finite float64 value, the SVG file will   > contain invalid  elements (although many SVG renderers handle   > this gracefully). Modify the program to skip invalid polygons.</p>
  </blockquote>
  
  <p>I was planing to solve it by adding the following to the corner func</p>
  
  <pre><code>if math.IsInf(z, 0) {
      return math.NaN(), math.NaN()
  }    
  </code></pre>
  
  <p>and changing the contents of the second for loop in main to</p>
  
  <pre><code>ax, ay := corner(i+1, j)
  if math.IsNaN(ax) {
      continue
  }
  bx, by := corner(i, j)
  if math.IsNaN(bx) {
      continue
  }
  cx, cy := corner(i, j+1)
  if math.IsNaN(cx) {
      continue
  }
  dx, dy := corner(i+1, j+1)
  if math.IsNaN(dx) {
      continue
  }
  fmt.Printf("&lt;polygon points='%g,%g %g,%g %g,%g %g,%g'/&gt;\n",
             ax, ay, bx, by, cx, cy, dx, dy)
  </code></pre>
  
  <p>I wanted to check my work so I decided to look up any answers other ppl had posted online to this problem. No one else that I found had used  <code>math.IsInf()</code>  in there solutions but most had used  <code>math.IsNaN()</code> . This made me wonder if I was missing some something and if  <code>math.IsNaN()</code>  was better for this purpose for some reason. So I looked through the Go Docs for both functions. I looked up NaN on wikipedia and the IEEE 754. I did general web searches for why everyone else was using  <code>math.IsNaN()</code>  even though it seemed less intuitive to me. Then I did searches on here and on stackoverflow for answers after all of that I didn't really have an answer so I decided to post a question.</p>