Precise floating-point<->string conversion

后端 未结 5 512
误落风尘
误落风尘 2020-12-09 05:03

I am looking for a library function to convert floating point numbers to strings, and back again, in C++. The properties I want are that str2num(num2str(x)) == x and that nu

5条回答
  •  孤街浪徒
    2020-12-09 05:50

    I am still unable to find a library that supplies the necessary code, but I did find some code that does work:

    http://svn.python.org/view/python/branches/py3k/Python/dtoa.c?view=markup

    By supplying a fairly small number of defines it's easy to abstract away the Python integration. This code does indeed meet all the properties I outline.

提交回复
热议问题