Modified compile-time type detection. Added test with tolerance.