How do I convert an arbitrary double to an integer while avoiding undefined behavior?

后端 未结 4 1657
你的背包
你的背包 2021-02-13 16:27

Let\'s say I\'ve got a function that accepts a 64-bit integer, and I want to call it with a double with arbitrary numeric value (i.e. it may be very large in magnit

4条回答
  •  情深已故
    2021-02-13 17:09

    boost::numeric_cast, that's how.

    http://www.boost.org/doc/libs/1_56_0/libs/numeric/conversion/doc/html/boost_numericconversion/improved_numeric_cast__.html

提交回复
热议问题