Computer Science, asked by kishoreananya, 6 months ago

is it safe to use the == operator to determine whether objects of type float are equal?​

Answers

Answered by msushanta088
4

Answer:

As has been shown comparing two floats (or doubles etc) can be problematic. Generally, instead of comparing for exact equality they should be checked against an error bound. If they are within the error bound, they are considered equal.

Answered by Jasleen0599
2

The Answer is No.

it is not safe to use the == operator to determine whether objects of type float are equal.

Explanation:

  • It's not true that numbers in floats are "identical to the bit" when == is used (the same number can be represented with different bit patterns, though only one of them is normalized form).
  • Additionally, the bit patterns used to indicate -0.0f and 0.0f (the sign bit is different) differ, although they compare as equal when using the operator == (but not with equals). In general, you are incorrect in your notion that bitwise comparison is what == means.
  • To begin with, do they float or float? Use the equals() method if one of them is a Float. Additionally, using the static Float is generally ideal. comparing approaches

#SPJ3

Similar questions