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

后端 未结 4 666
执笔经年
执笔经年 2021-02-13 16:28

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:00

    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

提交回复
热议问题