Вопрос по c++, performance – Преобразование double в char * в C ++ с высокой производительностью

24

Error: User Rate Limit Exceededsprintf()Error: User Rate Limit ExceededostringstreamError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded ratchet freak
Error: User Rate Limit Exceeded dbrank0
Error: User Rate Limit Exceededstackoverflow.com/questions/3173056/… nhahtdh

Ваш Ответ

8   ответов
1

ftoasprintf

ftoa

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
2

sprintf

double

itoa((int)((f + 0.00001) * 10000))

sprintfostream

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Shailesh Tainwala
Error: User Rate Limit Exceeded
17

EDIT:

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
2

Error: User Rate Limit ExceededdtostreError: User Rate Limit ExceededdtostrfError: User Rate Limit Exceededsprintf()Error: User Rate Limit Exceeded%e, %fError: User Rate Limit Exceeded%gError: User Rate Limit Exceeded

7

Error: User Rate Limit Exceeded

double dbl = 2222;
char* ptr = (char*)(&dbl);

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
2
/*

_ecvt_s Converts a double number to a string.

Syntax:

errno_t _ecvt_s( 
   char * _Buffer,
   size_t _SizeInBytes,
   double _Value,
   int _Count,
   int *_Dec,
   int *_Sign
);

[out] _Buffer
Filled with the pointer to the string of digits, the result of the conversion.

[in] _SizeInBytes
Size of the buffer in bytes.

[in] _Value
Number to be converted.

[in] _Count
Number of digits stored.

[out] _Dec
Stored decimal-point position.

[out] _Sign
Sign of the converted number.


*/


#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

...
char *buf = (char*) malloc(_CVTBUFSIZE);
int decimal;
int sign;
int err;


err = _ecvt_s(buf, _CVTBUFSIZE, 1.2, 5, &decimal, &sign);

if (err != 0) {
// implement error handling
}
else printf("Converted value: %s\n", buf);

...

Error: User Rate Limit Exceeded

3

9

Error: User Rate Limit ExceededwriteError: User Rate Limit ExceededreadError: User Rate Limit Exceeded

double value = 5.0;
std::ostream os;
//...
os.write(reinterpret_cast<const char*>(&value), sizeof(value));
//..
std::istream is;
is.read(reinterpret_cast<char*>(&value), sizeof(value));
Error: User Rate Limit Exceeded

Похожие вопросы