+// HexToFP - Convert the ascii string in hexidecimal format to the floating
+// point representation of it.
+//
+static double HexToFP(const char *Buffer) {
+ uint64_t Result = 0;
+ for (; *Buffer; ++Buffer) {
+ uint64_t OldRes = Result;
+ Result *= 16;
+ char C = *Buffer;
+ if (C >= '0' && C <= '9')
+ Result += C-'0';
+ else if (C >= 'A' && C <= 'F')
+ Result += C-'A'+10;
+ else if (C >= 'a' && C <= 'f')
+ Result += C-'a'+10;
+
+ if (Result < OldRes) // Uh, oh, overflow detected!!!
+ ThrowException("constant bigger than 64 bits detected!");
+ }
+
+ assert(sizeof(double) == sizeof(Result) &&
+ "Data sizes incompatible on this target!");
+ // Behave nicely in the face of C TBAA rules... see:
+ // http://www.nullstone.com/htmls/category/aliastyp.htm
+ //
+ char *ProxyPointer = (char*)&Result;
+ return *(double*)ProxyPointer; // Cast Hex constant to double
+}
+