Add rounding mode to VFPU
[ipdf/code.git] / src / tests / repr.cpp
diff --git a/src/tests/repr.cpp b/src/tests/repr.cpp
new file mode 100644 (file)
index 0000000..26ed668
--- /dev/null
@@ -0,0 +1,33 @@
+#include "main.h"
+
+#include <bitset>
+
+using namespace std;
+
+
+
+int main(int argc, char ** argv)
+{
+       char buffer[BUFSIZ];
+       double input;
+       printf("Enter a double: ");
+       fgets(buffer, BUFSIZ, stdin);
+       sscanf(buffer, "%lf", &input);
+
+
+       float f = (float)(input);
+
+       unsigned long long i;
+       memcpy(&i, &f, 4);
+       bitset<32> b32(i);
+       memcpy(&i, &input, 8);
+       bitset<64> b64(i);
+
+       printf("\nAs float: %s\n", b32.to_string().c_str());
+       printf("\nAs double: %s\n", b64.to_string().c_str());
+       #ifdef REAL_BITSET
+               Real r(input);
+               printf("\nAs real: %s\n", r.repr.to_string().c_str());
+       #endif //REAL_BITSET
+       
+}

UCC git Repository :: git.ucc.asn.au