How to check dependencies of floats

前端 未结 5 1255
闹比i
闹比i 2020-12-10 13:25

I want to determine (in c++) if one float number is the multiplicative inverse of another float number. The problem is that i have to use a third variable to do it. For inst

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 14:05

    What is striking is that whatever the rounding rule is, you expect the outcome of the two versions to be the same (either twice wrong or twice right)!

    Most probably, in the first case a promotion to higher accuracy in the FPU registers takes place when evaluating x==1/y, whereas z= 1/y really stores the single-precision result.

    Other contributors have explaine why 5==1/0.2 can fail, I needn't repeat that.

提交回复
热议问题