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/b995ebb0
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b995ebb0
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b995ebb0

Branch: refs/heads/master
Commit: b995ebb0ae323c8c0c4d4d7abc83b0885ff2d884
Parents: 8e07584
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Nov 10 17:48:50 2012 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Mon Nov 12 21:07:27 2012 +0100

----------------------------------------------------------------------
 clownfish/compiler/src/CFCPerlTypeMap.c            |    8 ++++++--
 .../runtime/core/Clownfish/Test/Util/TestMemory.c  |    5 +++--
 core/Lucy/Test/Search/TestSortSpec.c               |    4 ++--
 core/Lucy/Test/TestUtils.c                         |    2 +-
 core/Lucy/Test/Util/TestMemory.c                   |    5 +++--
 5 files changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b995ebb0/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/b995ebb0/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/b995ebb0/core/Lucy/Test/Search/TestSortSpec.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSortSpec.c 
b/core/Lucy/Test/Search/TestSortSpec.c
index 2d0fe28..00148fe 100644
--- a/core/Lucy/Test/Search/TestSortSpec.c
+++ b/core/Lucy/Test/Search/TestSortSpec.c
@@ -288,13 +288,13 @@ S_random_int64() {
 static Obj*
 S_random_float32() {
     uint64_t num = TestUtils_random_u64();
-    return (Obj*)Float32_new((double)num * (10.0 / U64_MAX));
+    return (Obj*)Float32_new(U64_TO_DOUBLE(num) * (10.0 / U64_MAX));
 }
 
 static Obj*
 S_random_float64() {
     uint64_t num = TestUtils_random_u64();
-    return (Obj*)Float64_new((double)num * (10.0 / U64_MAX));
+    return (Obj*)Float64_new(U64_TO_DOUBLE(num) * (10.0 / U64_MAX));
 }
 
 static VArray*

http://git-wip-us.apache.org/repos/asf/lucy/blob/b995ebb0/core/Lucy/Test/TestUtils.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/TestUtils.c b/core/Lucy/Test/TestUtils.c
index 1c467cc..28a6e91 100644
--- a/core/Lucy/Test/TestUtils.c
+++ b/core/Lucy/Test/TestUtils.c
@@ -72,7 +72,7 @@ TestUtils_random_f64s(double *buf, size_t count) {
     double *f64s = buf ? buf : (double*)CALLOCATE(count, sizeof(double));
     for (size_t i = 0; i < count; i++) {
         uint64_t num = TestUtils_random_u64();
-        f64s[i] = (double)num / U64_MAX;
+        f64s[i] = U64_TO_DOUBLE(num) / U64_MAX;
     }
     return f64s;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b995ebb0/core/Lucy/Test/Util/TestMemory.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestMemory.c b/core/Lucy/Test/Util/TestMemory.c
index 6aa0b0a..8ee03ef 100644
--- a/core/Lucy/Test/Util/TestMemory.c
+++ b/core/Lucy/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);

Reply via email to