Approximate equality: Difference between revisions

Content added Content deleted
Line 1,012: Line 1,012:
3.14159265358979323846 ≈ 3.14159265358979324</pre>
3.14159265358979323846 ≈ 3.14159265358979324</pre>
=={{header|Scala}}==
=={{header|Scala}}==
{{Out}}Best seen running in your browser by [https://scastie.scala-lang.org/z7su6JKJQC63UsteQesBiw Scastie (remote JVM)].
{{Out}}Best seen running in your browser by [https://scastie.scala-lang.org/kxD9xQuIQEGpABXnsE6BiQ Scastie (remote JVM)].


<lang Scala>object Approximate extends App {
<lang Scala>object Approximate extends App {
val (ok, notOk, ε) = ("👌", "❌", 1e-18)
val (ok, notOk, ε) = ("👌", "❌", 1e-18d)


private def approxEquals(value: Double, other: Double, epsilon: BigDecimal) =
private def approxEquals(value: Double, other: Double, epsilon: Double) =
scala.math.abs(value - other) < epsilon
scala.math.abs(value - other) < epsilon