Is casting of infinity to integer undefined?

前端 未结 3 1755
日久生厌
日久生厌 2021-01-17 07:18

Is the casting of infinity (represented by float) to an integer an undefined behavior?

The standard says:

4.10 Floating-integral conversions<

3条回答
  •  余生分开走
    2021-01-17 08:18

    I'm trying to understand why std::numeric_limits::infinity() and static_cast(std::numeric_limits::infinity() ) have different results.

    The standard says: 18.3.2.4

    static constexpr T infinity() noexcept;

    47 Representation of positive infinity, if available. [216]

    48 Meaningful for all specializations for which has_infinity != false. Required in specializations for which is_iec559 != false.

    --- edit ---

    According to 18.3.2.7/1 [numeric.special]

    1 All members shall be provided for all specializations. However, many values are only required to be meaningful under certain conditions (for example, epsilon() is only meaningful if is_integer is false). Any value that is not “meaningful” shall be set to 0 or false.

提交回复
热议问题