Use kotlin.math instead of java.lang.Math

Proprietary

Replaces JVM-only java.lang.Math calls with their multiplatform kotlin.math equivalents — top-level functions (abs, sqrt, sin, …), constants (PI, E), and receiver-style extensions on Double/Int/Long (pow, roundToInt, floorDiv, mod, …).

org.openrewrite.kotlin.migrate.UseKotlinMath$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.migrate.UseKotlinMath$KtRecipe'

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Use kotlin.math.abs instead of java.lang.Math.abs
  2. Use kotlin.math.sqrt instead of java.lang.Math.sqrt
  3. Use kotlin.math.floor instead of java.lang.Math.floor
  4. Use kotlin.math.ceil instead of java.lang.Math.ceil
  5. Use kotlin.math.min instead of java.lang.Math.min
  6. Use kotlin.math.max instead of java.lang.Math.max
  7. Use kotlin.math.exp instead of java.lang.Math.exp
  8. Use kotlin.math.ln instead of java.lang.Math.log
  9. Use kotlin.math.log10 instead of java.lang.Math.log10
  10. Use kotlin.math.sin instead of java.lang.Math.sin
  11. Use kotlin.math.cos instead of java.lang.Math.cos
  12. Use kotlin.math.tan instead of java.lang.Math.tan
  13. Use kotlin.math.asin instead of java.lang.Math.asin
  14. Use kotlin.math.acos instead of java.lang.Math.acos
  15. Use kotlin.math.atan instead of java.lang.Math.atan
  16. Use kotlin.math.atan2 instead of java.lang.Math.atan2
  17. Use kotlin.math.sinh instead of java.lang.Math.sinh
  18. Use kotlin.math.cosh instead of java.lang.Math.cosh
  19. Use kotlin.math.tanh instead of java.lang.Math.tanh
  20. Use kotlin.math.cbrt instead of java.lang.Math.cbrt
  21. Use kotlin.math.hypot instead of java.lang.Math.hypot
  22. Use kotlin.math.expm1 instead of java.lang.Math.expm1
  23. Use kotlin.math.ln1p instead of java.lang.Math.log1p
  24. Use kotlin.math.sign instead of java.lang.Math.signum
  25. Use kotlin.math.PI instead of java.lang.Math.PI
  26. Use kotlin.math.E instead of java.lang.Math.E
  27. Use Double.pow instead of java.lang.Math.pow
  28. Use Double.roundToLong() instead of java.lang.Math.round
  29. Use Float.roundToInt() instead of java.lang.Math.round
  30. Use Double.withSign instead of java.lang.Math.copySign
  31. Use Double.IEEErem instead of java.lang.Math.IEEEremainder
  32. Use Double.nextUp() instead of java.lang.Math.nextUp
  33. Use Double.nextDown() instead of java.lang.Math.nextDown
  34. Use Double.nextTowards() instead of java.lang.Math.nextAfter
  35. Use Int.floorDiv instead of java.lang.Math.floorDiv
  36. Use Long.floorDiv instead of java.lang.Math.floorDiv
  37. Use Int.mod() instead of java.lang.Math.floorMod
  38. Use Long.mod() instead of java.lang.Math.floorMod
  39. Use Long.mod(Int) instead of java.lang.Math.floorMod