[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

Steve Canon via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 7 12:04:11 PST 2018


scanon added inline comments.


================
Comment at: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp:187
+  assert(std::fabs(v[0] - 0.0f) < FLT_EPSILON);
+  assert(std::fabs(v[1] - 1.0f) < FLT_EPSILON);
+  assert(std::fabs(v[2] - 2.0f) < FLT_EPSILON);
----------------
These comparisons with `FLT_EPSILON` are doing nothing but adding noise. There is no value other than 2 that can possibly satisfy `fabs(v[2] - 2.0f) < FLT_EPSILON`, so this test can simply be `v[2] == 2`, for example.

If you find yourself using `FLT_EPSILON` as a tolerance, it's almost always wrong.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48342/new/

https://reviews.llvm.org/D48342





More information about the cfe-commits mailing list