Finding the closest floating point value less than a specific integer value in C++?

前端 未结 2 448
说谎
说谎 2020-12-22 03:18

I have an input floating point value that is 0.0f <= value < 1.0f (note less than one).

When multiplying this value up to a larger range, naturally the floatin

2条回答
  •  无人及你
    2020-12-22 03:48

    I'm hoping there's a magic instruction I'm not aware of that I can use to achieve this!

    If you've got a C++11 (or C99) standard library, then std::nextafter(value, 0.0f) from (or nextafter from ) will give you the largest representable value smaller than value.

    It gives the "next" distinct value after the first argument, in the direction of the second; so here, the next distinct value closer to zero.

提交回复
热议问题