Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. comparing floating point numbers in C for unit testing
  2. float x;
  3. x = atof("17.99");
  4.        
  5. CU_ASSERT(abs(x - atof("17.99")) < epsilon);
  6.        
  7. r = atof("17.99");
  8. CU_ASSERT(0 == memcmp(&x, &r, sizeof(float));
  9.        
  10. float r, x;
  11.  
  12. r = atof("17.99");
  13. CU_ASSERT(0 == memcmp(&x, &r, sizeof(float));
  14.        
  15. r = atof("17.99");
  16. CU_ASSERT(x == r);
  17.        
  18. CU_ASSERT(x == atof("17.99"));
  19.        
  20. CU_ASSERT(x == (float)atof("17.99"));