MCPcopy Create free account
hub / github.com/SOUI2/soui / normalizeFloatingPointStr

Function normalizeFloatingPointStr

third-part/jsoncpp/src/jsontestrunner/main.cpp:30–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28};
29
30static JSONCPP_STRING normalizeFloatingPointStr(double value) {
31 char buffer[32];
32#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
33 sprintf_s(buffer, sizeof(buffer), "%.16g", value);
34#else
35 snprintf(buffer, sizeof(buffer), "%.16g", value);
36#endif
37 buffer[sizeof(buffer) - 1] = 0;
38 JSONCPP_STRING s(buffer);
39 JSONCPP_STRING::size_type index = s.find_last_of("eE");
40 if (index != JSONCPP_STRING::npos) {
41 JSONCPP_STRING::size_type hasSign =
42 (s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
43 JSONCPP_STRING::size_type exponentStartIndex = index + 1 + hasSign;
44 JSONCPP_STRING normalized = s.substr(0, exponentStartIndex);
45 JSONCPP_STRING::size_type indexDigit =
46 s.find_first_not_of('0', exponentStartIndex);
47 JSONCPP_STRING exponent = "0";
48 if (indexDigit !=
49 JSONCPP_STRING::npos) // There is an exponent different from 0
50 {
51 exponent = s.substr(indexDigit);
52 }
53 return normalized + exponent;
54 }
55 return s;
56}
57
58static JSONCPP_STRING readInputTestFile(const char* path) {
59 FILE* file = fopen(path, "rb");

Callers 2

printValueTreeFunction · 0.85
JSONTEST_FIXTUREFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected