TIL NaNs and infinities slow down programs

Revision en1, by johnchen902, 2016-07-19 21:06:10

Today I learned that NaNs and infinites may slow down programs significantly. So instead of

// some computation that produce NaN when arg == 0
if(arg == 0) // special case
    result = 0;

one should write

if(arg == 0)
    result = 0; // special case
else
    // some computation that produce NaN when arg == 0

Compare submission 19257027 and 19257693 and you'll see.

Tags floating-point

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English johnchen902 2016-07-19 21:06:10 483 Initial revision (published)