How to alter a float by its smallest increment (or close to it)?

前端 未结 7 1219
余生分开走
余生分开走 2020-11-30 02:05

I have a double value f and would like a way to nudge it very slightly larger (or smaller) to get a new value that will be as close as possible to

7条回答
  •  青春惊慌失措
    2020-11-30 02:47

    This may not be exactly what you want, but you still might find numeric_limits in of use. Particularly the members min(), and epsilon().

    I don't believe that something like mydouble + numeric_limits::epsilon() will do what you want, unless mydouble is already close to epsilon. If it is, then you're in luck.

提交回复
热议问题