Updated Branches:
  refs/heads/msvc6 94be23f76 -> baaf13b3e

Use new CHY_U64_TO_DOUBLE macro


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/baaf13b3
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/baaf13b3
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/baaf13b3

Branch: refs/heads/msvc6
Commit: baaf13b3e0c65df189ace733c1bb65f820b6944c
Parents: 6ee5759
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Nov 10 17:48:50 2012 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat Nov 10 17:48:50 2012 +0100

----------------------------------------------------------------------
 clownfish/compiler/src/CFCPerlTypeMap.c            |    8 ++++-
 .../runtime/core/Clownfish/Test/Util/TestMemory.c  |    5 ++-
 core/Lucy/Test/Util/TestMemory.c                   |   20 ++------------
 3 files changed, 12 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/baaf13b3/clownfish/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCPerlTypeMap.c 
b/clownfish/compiler/src/CFCPerlTypeMap.c
index 7525d70..70bd654 100644
--- a/clownfish/compiler/src/CFCPerlTypeMap.c
+++ b/clownfish/compiler/src/CFCPerlTypeMap.c
@@ -160,7 +160,9 @@ CFCPerlTypeMap_to_perl(CFCType *type, const char *cf_var) {
             sprintf(result, "newSViv(%s)", cf_var);
         }
         else if (strcmp(specifier, "uint64_t") == 0) {
-            char pattern[] = "sizeof(UV) == 8 ? newSVuv((UV)%s) : 
newSVnv((NV)%s)";
+            char pattern[] =
+                "sizeof(UV) == 8 ? "
+                "newSVuv((UV)%s) : newSVnv((NV)CHY_U64_TO_DOUBLE(%s))";
             sprintf(result, pattern, cf_var, cf_var);
         }
         else if (strcmp(specifier, "uint32_t") == 0) {
@@ -262,7 +264,9 @@ static const char typemap_output[] =
     "\n"
     "CHY_BIG_UNSIGNED_INT\n"
     "    if (sizeof(UV) == 8) { sv_setuv($arg, (UV)$var); }\n"
-    "    else                 { sv_setnv($arg, (NV)$var); }\n"
+    "    else {\n"
+    "        sv_setnv($arg, (NV)CHY_U64_TO_DOUBLE($var));\n"
+    "    }\n"
     "\n";
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/baaf13b3/clownfish/runtime/core/Clownfish/Test/Util/TestMemory.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/Util/TestMemory.c 
b/clownfish/runtime/core/Clownfish/Test/Util/TestMemory.c
index fbeff48..642c420 100644
--- a/clownfish/runtime/core/Clownfish/Test/Util/TestMemory.c
+++ b/clownfish/runtime/core/Clownfish/Test/Util/TestMemory.c
@@ -42,7 +42,8 @@ test_oversize__growth_rate(TestBatch *batch) {
         }
         if (size > 0) {
             growth_count += 1;
-            double growth_rate = (double)next_size / (double)size;
+            double growth_rate = U64_TO_DOUBLE(next_size) /
+                                 U64_TO_DOUBLE(size);
             double sum = growth_rate + (growth_count - 1) * 
average_growth_rate;
             average_growth_rate = sum / growth_count;
             if (average_growth_rate < 1.1) {
@@ -63,7 +64,7 @@ test_oversize__growth_rate(TestBatch *batch) {
 
     for (int minimum = 1; minimum < 8; minimum++) {
         uint64_t next_size = Memory_oversize(minimum, sizeof(void*));
-        double growth_rate = (double)next_size / (double)minimum;
+        double growth_rate = U64_TO_DOUBLE(next_size) / (double)minimum;
         TEST_TRUE(batch, growth_rate > 1.2,
                   "Growth rate is higher for smaller arrays (%d, %.3f)", 
minimum,
                   growth_rate);

http://git-wip-us.apache.org/repos/asf/lucy/blob/baaf13b3/core/Lucy/Test/Util/TestMemory.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestMemory.c b/core/Lucy/Test/Util/TestMemory.c
index 187fdec..8ee03ef 100644
--- a/core/Lucy/Test/Util/TestMemory.c
+++ b/core/Lucy/Test/Util/TestMemory.c
@@ -25,20 +25,6 @@
   #define SIZE_MAX ((size_t)-1)
 #endif
 
-/* MSVC6 doesn't support conversion of unsigned __int64 to double.
- */
-static double
-S_u64_to_double(uint64_t num) {
-    if (num & U64_C(0x8000000000000000)) {
-        /* Most significant bit is set */
-        int64_t lower_63_bits = (int64_t)(num & U64_C(0x7FFFFFFFFFFFFFFF));
-        return (double)lower_63_bits + 9223372036854775808.0;
-    }
-    else {
-        return (double)(int64_t)num;
-    }
-}
-
 static void
 test_oversize__growth_rate(TestBatch *batch) {
     bool_t   success             = true;
@@ -56,8 +42,8 @@ test_oversize__growth_rate(TestBatch *batch) {
         }
         if (size > 0) {
             growth_count += 1;
-            double growth_rate = S_u64_to_double(next_size) /
-                                 S_u64_to_double(size);
+            double growth_rate = U64_TO_DOUBLE(next_size) /
+                                 U64_TO_DOUBLE(size);
             double sum = growth_rate + (growth_count - 1) * 
average_growth_rate;
             average_growth_rate = sum / growth_count;
             if (average_growth_rate < 1.1) {
@@ -78,7 +64,7 @@ test_oversize__growth_rate(TestBatch *batch) {
 
     for (int minimum = 1; minimum < 8; minimum++) {
         uint64_t next_size = Memory_oversize(minimum, sizeof(void*));
-        double growth_rate = S_u64_to_double(next_size) / (double)minimum;
+        double growth_rate = U64_TO_DOUBLE(next_size) / (double)minimum;
         TEST_TRUE(batch, growth_rate > 1.2,
                   "Growth rate is higher for smaller arrays (%d, %.3f)", 
minimum,
                   growth_rate);

Reply via email to