Converting double to char* in C++ with high performance

后端 未结 8 1547
野趣味
野趣味 2020-12-15 04:23

My application needs to convert double values to char* to write to a pipe that accepts only characters. The usual ways of doing this are using the sprintf() functio

8条回答
  •  死守一世寂寞
    2020-12-15 04:49

    Using ftoawill be slightly better than sprintf as this is what it is using internally. See related question here Also look at how ftoa is implemented in your library source and see if you can improve on it for your specific scenarios.

    It seems ftoa is not standard at all, my bad. Here's a discussion showing an implementation which claims to be far faster that sprintf. You'd need to profile both on your own target environments, and implement with double rather than float.

提交回复
热议问题