next higher/lower IEEE double precision number

后端 未结 6 1840
我寻月下人不归
我寻月下人不归 2020-12-03 07:27

I am doing high precision scientific computations. In looking for the best representation of various effects, I keep coming up with reasons to want to get the next higher (

6条回答
  •  無奈伤痛
    2020-12-03 07:43

    There are functions available for doing exactly that, but they can depend on what language you use. Two examples:

    • if you have access to a decent C99 math library, you can use nextafter (and its float and long double variants, nextafterf and nextafterl); or the nexttoward family (which take a long double as second argument).

    • if you write Fortran, you have the nearest intrinsic available

    If you can't access these directly from your language, you can also look at how they're implemented in freely available, such as this one.

提交回复
热议问题