What's the first double that deviates from its corresponding long by delta?

前端 未结 4 1458
遥遥无期
遥遥无期 2021-01-18 18:14

I want to know the first double from 0d upwards that deviates by the long of the \"same value\" by some delta, say 1e-8. I\'m failing here though. I\'m trying to do this i

4条回答
  •  逝去的感伤
    2021-01-18 18:31

    Although I'm hesitant to mention Fortran 95 and successors in this discussion, I'll mention that Fortran since the 1990 standard has offered a SPACING intrinsic function which tells you what the difference between representable REALs are about a given REAL. You could do a binary search on this, stopping when SPACING(X) > DELTA. For compilers that use the same floating point model as the one you are interested in (likely to be the IEEE754 standard), you should get the same results.

提交回复
热议问题