You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since floating-point numbers have precision problems in computer representation - as it was recommended in
Rule 4.1.1 - better to use BigDecimal instead when you need to make accurate computations and comparison.
The following code describes these problems:
val f1 =1.0f-0.9fval f2 =0.9f-0.8fif (f1 == f2) {
println("Expected to enter here")
} else {
println("But this block will be reached")
}
val flt1 = f1;
val flt2 = f2;
if (flt1.equals(flt2)) {
println("Expected to enter here")
} else {
println("But this block will be reached")
}
Recommended example:
val foo =1.03fval bar =0.42fif (abs(foo - bar) > 1e-6f) {
println("Ok")
} else {
println("Not")
}
The text was updated successfully, but these errors were encountered:
Partially done in #303 , this part can be edited as follows:
'Binary operations on floats are prohibited, the only exception is comparison of absolute value of difference'
Since floating-point numbers have precision problems in computer representation - as it was recommended in
Rule 4.1.1 - better to use BigDecimal instead when you need to make accurate computations and comparison.
The following code describes these problems:
Recommended example:
The text was updated successfully, but these errors were encountered: