1. Vulnerability Description
- If a formula is configured arbitrarily, significant loss of accuracy may occur.
2. Vulnerability Countermeasure
- Use a funtion that fits your purpose.
3. Sample Code
(1) Cbrt
class Test {
scala.math.pow(x, 1/3d)
math.pow(x, 1/3d)
}
class Test {
math.cbrt(x)
}
(2) ExpM1
class Test {
math.exp(x) - 1
}
class Test {
math.expm1(x)
}
(3) Log10
class Test {
math.log(x)/math.log(10)
}
class Test {
math.log10(x)
}
(4) Log1P
class Test {
math.log(x + 1)
}
class Test {
math.log1p(x)
}
(5) Sqrt
class Test {
scala.math.pow(2, 0.5)
}
class Test {
math.sqrt(x)
}