MCPcopy Create free account
hub / github.com/Kitware/VTK / ConvertStringToDouble

Function ConvertStringToDouble

IO/PostgreSQL/vtkPostgreSQLQuery.cxx:889–963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

887//------------------------------------------------------------------------------
888
889vtkVariant ConvertStringToDouble(bool isBinary, const char* rawData)
890{
891 if (isBinary)
892 {
893 // As of PostgreSQL version 8.3.0, libpq transmits a float in network
894 // byte order -- that is, it reinterprets the bits as an unsigned int
895 // and then transmits them that way. This... frightens me. It assumes
896 // that both sender and recipient use IEEE floats. Still, I'm not sure
897 // there's any other good way to do it.
898
899 // Let's hope that we always have a 64-bit type.
900 vtkTypeUInt64 intResult;
901 ConvertFromNetworkOrder(intResult, rawData);
902 union
903 {
904 vtkTypeUInt64 i;
905 double d;
906 } swap;
907 swap.i = intResult;
908 return vtkVariant(swap.d);
909 }
910 else
911 {
912 double finalResult;
913 std::string rawString(rawData);
914
915 // Catch NaN
916 if (rawData[0] == 'N' || rawData[0] == 'n')
917 {
918 if (std::numeric_limits<double>::has_quiet_NaN)
919 {
920 finalResult = std::numeric_limits<double>::quiet_NaN();
921 }
922 else
923 {
924 // C99 defines a NAN macro. If it's there, that solves our problem.
925#if defined(NAN)
926 finalResult = NAN;
927#else
928 double zero = 0.0;
929 finalResult = zero / zero;
930#endif
931 }
932 }
933 else if (rawString == "Infinity")
934 {
935 if (std::numeric_limits<double>::has_infinity)
936 {
937 finalResult = std::numeric_limits<double>::infinity();
938 }
939 else
940 {
941 finalResult = VTK_DOUBLE_MAX;
942 }
943 }
944 else if (rawString == "-Infinity")
945 {
946 if (std::numeric_limits<double>::has_infinity)

Callers 1

DataValueMethod · 0.85

Calls 3

ConvertFromNetworkOrderFunction · 0.85
vtkVariantClass · 0.70
ToDoubleMethod · 0.45

Tested by

no test coverage detected