MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / floatHexToDoubleNumber

Function floatHexToDoubleNumber

lib/mathlib.cpp:497–505  ·  view source on GitHub ↗

Assuming a limited support of built-in hexadecimal floats (see C99, C++17) that is a fall-back implementation. Performance has been optimized WRT to heap activity, however the calculation part is not optimized.

Source from the content-addressed store, hash-verified

495// Assuming a limited support of built-in hexadecimal floats (see C99, C++17) that is a fall-back implementation.
496// Performance has been optimized WRT to heap activity, however the calculation part is not optimized.
497static double floatHexToDoubleNumber(const std::string& str)
498{
499 const std::size_t p = str.find_first_of("pP",3);
500 const double factor1 = myStod(str, str.cbegin() + 2, str.cbegin()+p, 16);
501 const bool suffix = (str.back() == 'f') || (str.back() == 'F') || (str.back() == 'l') || (str.back() == 'L');
502 const double exponent = myStod(str, str.cbegin() + p + 1, suffix ? str.cend()-1:str.cend(), 10);
503 const double factor2 = std::pow(2, exponent);
504 return factor1 * factor2;
505}
506
507double MathLib::toDoubleNumber(const Token * tok)
508{

Callers 1

toDoubleNumberMethod · 0.85

Calls 1

myStodFunction · 0.85

Tested by

no test coverage detected