If I copy a float to another variable, will they be equal?

后端 未结 5 1046
猫巷女王i
猫巷女王i 2021-01-30 00:11

I know that using == to check equality of floating-point variables is not a good way. But I just want to know that with the following statements:



        
5条回答
  •  鱼传尺愫
    2021-01-30 00:24

    In usual cases, it would evaluate to true. (or the assert statement won't do anything)

    Edit:

    By 'usual cases' I mean am excluding the aforementioned scenarios (such as NaN values and 80x87 floating point units) as pointed by other users.

    Given the obsolesence of 8087 chips in today's context, the issue is rather isolated and for the question to be applicable in current state of floating-point architecture used, its true for all cases except for NaNs.

    (reference about 8087 - https://home.deec.uc.pt/~jlobo/tc/artofasm/ch14/ch143.htm)

    Kudos to @chtz for reproducing a good example and @kmdreko for mentioning NaNs - didn't knew about them before!

提交回复
热议问题