Open ptheywood opened 10 months ago
The following appears to work for values tested so far. Not the cheapest method so worth only doing this once on the host and storing if wrapped is available for a given spatial message list on the device, rather than doing this per call to the wrapped iterator on the device
template <typename T>
bool approxExactlyDivisible(T a, T b) {
// Scale machine epsilon by the magnitude of the larger value
T scaledEpsilon = std::max(std::abs(a), std::abs(b)) * std::numeric_limits<T>::epsilon();
// Compute the remainder
T v = std::fmod(a, b);
// approx equal if the remainder is within scaledEpsilon of 0 or b (fmod(1, 0.05f) returns ~0.05f)
return v <= scaledEpsilon || v > b - scaledEpsilon;
}
0.05
Closes #1177