You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/11/10 16:30:13 UTC
[lucy-commits] [2/3] git commit: refs/heads/msvc6 - TestMemory.c must work with
numbers >= 2^63
TestMemory.c must work with numbers >= 2^63
Add a function to convert unsigned __int64 to double for MSVC6.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b4181165
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b4181165
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b4181165
Branch: refs/heads/msvc6
Commit: b41811658f105db6aad6379b1f6554fed35924a4
Parents: 2febdf9
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Nov 10 16:23:22 2012 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Nov 10 16:28:26 2012 +0100
----------------------------------------------------------------------
core/Lucy/Test/Util/TestMemory.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/b4181165/core/Lucy/Test/Util/TestMemory.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestMemory.c b/core/Lucy/Test/Util/TestMemory.c
index 2707cd3..187fdec 100644
--- a/core/Lucy/Test/Util/TestMemory.c
+++ b/core/Lucy/Test/Util/TestMemory.c
@@ -25,15 +25,29 @@
#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;
- int64_t size = 0;
- double growth_count = 0;
- double average_growth_rate = 0.0;
+ bool_t success = true;
+ uint64_t size = 0;
+ double growth_count = 0;
+ double average_growth_rate = 0.0;
while (size < SIZE_MAX) {
- int64_t next_size = Memory_oversize((size_t)size + 1, sizeof(void*));
+ uint64_t next_size = Memory_oversize((size_t)size + 1, sizeof(void*));
if (next_size < size) {
success = false;
FAIL(batch, "Asked for %" I64P ", got smaller amount %" I64P,
@@ -42,7 +56,8 @@ test_oversize__growth_rate(TestBatch *batch) {
}
if (size > 0) {
growth_count += 1;
- double growth_rate = (double)next_size / (double)size;
+ double growth_rate = S_u64_to_double(next_size) /
+ S_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 +78,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 = S_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);