Skip to content

math/prefer-math-log2e

enforce the use of Math.LOG2E instead of other ways

  • ⚙️ 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.LOG2E instead of other ways to represent the base-2 logarithm of Euler's number (e).

Math.LOG2E provides several advantages over manual calculations:

  • Clarity of intent: Immediately obvious that you're using the base-2 logarithm of e
  • Precision: Provides the most accurate representation available in JavaScript
  • Performance: Direct constant access instead of function call overhead
  • Consistency: Part of the standardized Math constants family
  • Computational efficiency: Avoids floating-point division operations
Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-math v0.4.0

🔍 Implementation