math/prefer-math-sum-precise
enforce the use of Math.sumPrecise() instead of other summation methods
- 🔧 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.sumPrecise()
instead of other summation methods.
Math.sumPrecise()
addresses floating-point precision issues that occur with traditional summation approaches:
- More precise algorithm: Uses a more precise algorithm than naive summation
- Consistency: Standardized approach to precise summation
- Performance: Optimized implementation in the JavaScript engine
🔧 Options
json
{
"math/abs": [
"error",
{
"aggressive": false
}
]
}
aggressive
... configure the aggressive mode for only this rule. (default:false
)
The aggressive
mode
This plugin never reports expressions with unknown type by default. Because it's hard to know the type of objects, it will cause false positives.
If you configured the aggressive
mode, this plugin reports expressions with unknown type even if the rules couldn't know the type of operands.
📚 Further reading
🚀 Version
This rule was introduced in eslint-plugin-math v0.11.0