math/prefer-math-log2
enforce the use of Math.log2() instead of other calculation methods.
- ⚙️ This rule is included in
"plugin:math/recommended"
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule. - 💡 Some problems reported by this rule are manually fixable by editor suggestions.
📖 Rule Details
This rule aims to enforce the use of Math.log2()
instead of other calculation methods for computing base-2 logarithms.
Math.log2()
provides several advantages over manual calculations:
- Clarity of intent: Immediately obvious that you're calculating a base-2 logarithm
- Performance: Optimized native implementation, potentially faster than manual calculations
- Precision: More accurate for edge cases and special values
- Computer science relevance: Base-2 is fundamental in computing and algorithms
- Consistency: Part of the ES2015 Math API family
🔧 Options
Nothing.
📚 Further reading
🚀 Version
This rule was introduced in eslint-plugin-math v0.4.0