diff --git a/mak/COPY b/mak/COPY
index e823ec5a43e..87ddb28a4d9 100644
--- a/mak/COPY
+++ b/mak/COPY
@@ -12,10 +12,10 @@ COPY=\
$(IMPDIR)\core\thread.di \
$(IMPDIR)\core\time.d \
$(IMPDIR)\core\vararg.d \
- \
- $(IMPDIR)\core\internal\hash.d \
- $(IMPDIR)\core\internal\convert.d \
- \
+ \
+ $(IMPDIR)\core\internal\hash.d \
+ $(IMPDIR)\core\internal\convert.d \
+ \
$(IMPDIR)\core\stdc\complex.d \
$(IMPDIR)\core\stdc\config.d \
$(IMPDIR)\core\stdc\ctype.d \
diff --git a/mak/MANIFEST b/mak/MANIFEST
index cbeadd4f01d..ec8f9e26665 100644
--- a/mak/MANIFEST
+++ b/mak/MANIFEST
@@ -31,10 +31,10 @@ MANIFEST=\
src\core\threadasm.S \
src\core\time.d \
src\core\vararg.d \
- \
- src\core\internal\hash.d \
- src\core\internal\convert.d \
- \
+ \
+ src\core\internal\hash.d \
+ src\core\internal\convert.d \
+ \
src\core\stdc\complex.d \
src\core\stdc\config.d \
src\core\stdc\ctype.d \
diff --git a/mak/SRCS b/mak/SRCS
index 17d84311dd2..9d84a78f6e7 100644
--- a/mak/SRCS
+++ b/mak/SRCS
@@ -13,10 +13,10 @@ SRCS=\
src\core\thread.d \
src\core\time.d \
src\core\vararg.d \
- \
- src\core\internal\hash.d \
- src\core\internal\convert.d \
- \
+ \
+ src\core\internal\hash.d \
+ src\core\internal\convert.d \
+ \
src\core\stdc\config.d \
src\core\stdc\ctype.d \
src\core\stdc\errno.d \
diff --git a/src/core/internal/convert.d b/src/core/internal/convert.d
index c8151b7016d..1dc62734afb 100644
--- a/src/core/internal/convert.d
+++ b/src/core/internal/convert.d
@@ -1,3 +1,12 @@
+/**
+ * Written in the D programming language.
+ * This module provides functions to converting different values to const(ubyte)[]
+ *
+ * Copyright: Copyright Igor Stepanov 2013-2013.
+ * License: Boost License 1.0.
+ * Authors: Igor Stepanov
+ * Source: $(DRUNTIMESRC core/internal/_convert.d)
+ */
module core.internal.convert;
@trusted pure nothrow
@@ -68,8 +77,8 @@ private Float parse(bool is_denormalized = false, T)(T x) if(is(T == float) || i
if(x is cast(T)-0.0) return FloatTraits!T.NZERO;
if(x is T.nan) return FloatTraits!T.NAN;
if(x is -T.nan) return FloatTraits!T.NNAN;
- if(x is T.infinity) return FloatTraits!T.INF;
- if(x is -T.infinity) return FloatTraits!T.NINF;
+ if(x is T.infinity || x > T.max) return FloatTraits!T.INF;
+ if(x is -T.infinity || x < -T.max) return FloatTraits!T.NINF;
uint sign = x < 0;
x = sign ? -x : x;
@@ -79,7 +88,10 @@ private Float parse(bool is_denormalized = false, T)(T x) if(is(T == float) || i
if(!exp)
{
- return Float(denormalizedMantissa(x), 0, sign);
+ if(is_denormalized)
+ return Float(0, 0, sign);
+ else
+ return Float(denormalizedMantissa(x), 0, sign);
}
x2 /= binPow2(e);
@@ -339,6 +351,21 @@ version(unittest)
testNumberConvert!("0.0Fi");
testNumberConvert!("0.0i");
testNumberConvert!("0.0Li");
+
+ testNumberConvert!("cast(real)-0x9.0f7ee55df77618fp-13829L");
+ testNumberConvert!("cast(real)0x7.36e6e2640120d28p+8797L");
+ testNumberConvert!("cast(real)-0x1.05df6ce4702ccf8p+15835L");
+ testNumberConvert!("cast(real)0x9.54bb0d88806f714p-7088L");
+
+ testNumberConvert!("cast(double)-0x9.0f7ee55df77618fp-13829L");
+ testNumberConvert!("cast(double)0x7.36e6e2640120d28p+8797L");
+ testNumberConvert!("cast(double)-0x1.05df6ce4702ccf8p+15835L");
+ testNumberConvert!("cast(double)0x9.54bb0d88806f714p-7088L");
+
+ testNumberConvert!("cast(float)-0x9.0f7ee55df77618fp-13829L");
+ testNumberConvert!("cast(float)0x7.36e6e2640120d28p+8797L");
+ testNumberConvert!("cast(float)-0x1.05df6ce4702ccf8p+15835L");
+ testNumberConvert!("cast(float)0x9.54bb0d88806f714p-7088L");
}
@@ -348,12 +375,6 @@ version(unittest)
}
}
-
-
-
-
-
-
private template Unqual(T)
{
static if (is(T U == shared(const U))) alias U Unqual;
@@ -372,7 +393,7 @@ const(ubyte)[] toUbyte(T)(T[] arr) if (T.sizeof == 1)
}
@trusted pure nothrow
-const(ubyte)[] toUbyte(T)(T[] arr) if (is(typeof(toUbyte(arr[0])) == const(ubyte)[]))
+const(ubyte)[] toUbyte(T)(T[] arr) if ((is(typeof(toUbyte(arr[0])) == const(ubyte)[]))&&(T.sizeof > 1))
{
if (__ctfe)
{
@@ -527,4 +548,4 @@ const(ubyte)[] toUbyte(T)(ref T val) if (is(T == struct) || is(T == union))
{
return (cast(const(ubyte)*)&val)[0 .. T.sizeof];
}
-}
\ No newline at end of file
+}
diff --git a/src/core/internal/hash.d b/src/core/internal/hash.d
index 11bc265e7f3..43a1e32b36f 100644
--- a/src/core/internal/hash.d
+++ b/src/core/internal/hash.d
@@ -1,16 +1,15 @@
/**
- * Hash uniform caluclation implementation
+ * Written in the D programming language.
+ * This module provides functions to uniform calculating hash values for different types
*
- * Author: Igor Stepanov
- *
+ * Copyright: Copyright Igor Stepanov 2013-2013.
+ * License: Boost License 1.0.
+ * Authors: Igor Stepanov
+ * Source: $(DRUNTIMESRC core/internal/_hash.d)
*/
-
module core.internal.hash;
import core.internal.convert;
-/**
- Compute hash value for different types.
-*/
//enum hash. CTFE depends on base type
@trusted nothrow
@@ -64,6 +63,7 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T S:
}
else //Other types. CTFE unsupported
{
+ assert(!__ctfe, "unable to compute hash of "~T.stringof);
return bytesHash(val.ptr, ElementType.sizeof*val.length, seed);
}
}
@@ -72,23 +72,15 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T S:
@trusted nothrow pure
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && __traits(isArithmetic, T))
{
- static if (is(typeof(toUbyte(val)) == const(ubyte)[])) //most of numerics CTFE ready
+ static if(__traits(isFloating, val))
{
- static if(__traits(isFloating, val))
- {
- T data = (val != val) ? T.nan : val;
- auto bytes = toUbyte(data);
- return bytesHash(bytes.ptr, bytes.length, seed);
- }
- else
- {
- auto bytes = toUbyte(val);
- return bytesHash(bytes.ptr, bytes.length, seed);
- }
+ T data = (val != val) ? T.nan : val;
+ auto bytes = toUbyte(data);
+ return bytesHash(bytes.ptr, bytes.length, seed);
}
- else //real, ireal, creal. CTFE unsupproted
+ else
{
- const(ubyte)[] bytes = (cast(const(ubyte)*)&val)[0 .. T.sizeof];
+ auto bytes = toUbyte(val);
return bytesHash(bytes.ptr, bytes.length, seed);
}
}
@@ -127,6 +119,7 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && (is(T ==
}
else // CTFE unsupproreted for structs with reference fields
{
+ assert(!__ctfe, "unable to compute hash of "~T.stringof);
const(ubyte)[] bytes = (cast(const(ubyte)*)&val)[0 .. T.sizeof];
return bytesHash(bytes.ptr, bytes.length, seed);
}
@@ -136,6 +129,7 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && (is(T ==
@trusted nothrow pure
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T == delegate))
{
+ assert(!__ctfe, "unable to compute hash of "~T.stringof);
const(ubyte)[] bytes = (cast(const(ubyte)*)&val)[0 .. T.sizeof];
return bytesHash(bytes.ptr, bytes.length, seed);
}
@@ -404,9 +398,9 @@ version(AnyX86)
@trusted pure nothrow
size_t bytesHash(const(void)* buf, size_t len, size_t seed = 0)
{
- static uint rotl32(uint x, byte r) pure nothrow @safe
+ static uint rotl32(uint n)(in uint x) pure nothrow @safe
{
- return (x << r) | (x >> (32 - r));
+ return (x << n) | (x >> (32 - n));
}
//-----------------------------------------------------------------------------
@@ -459,11 +453,11 @@ size_t bytesHash(const(void)* buf, size_t len, size_t seed = 0)
{
uint k1 = get32bits(data);
k1 *= c1;
- k1 = rotl32(k1,15);
+ k1 = rotl32!15(k1);
k1 *= c2;
h1 ^= k1;
- h1 = rotl32(h1,13);
+ h1 = rotl32!13(h1);
h1 = h1*5+c3;
}
@@ -476,7 +470,7 @@ size_t bytesHash(const(void)* buf, size_t len, size_t seed = 0)
case 3: k1 ^= data[2] << 16; goto case;
case 2: k1 ^= data[1] << 8; goto case;
case 1: k1 ^= data[0];
- k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1;
+ k1 *= c1; k1 = rotl32!15(k1); k1 *= c2; h1 ^= k1;
goto default;
default:
}
diff --git a/win32.mak b/win32.mak
index 3f5cbfad8d8..741db6d8edf 100644
--- a/win32.mak
+++ b/win32.mak
@@ -183,10 +183,10 @@ $(IMPDIR)\core\vararg.d : src\core\vararg.d
copy $** $@
$(IMPDIR)\core\internal\hash.d : src\core\internal\hash.d
- copy $** $@
+ copy $** $@
$(IMPDIR)\core\internal\convert.d : src\core\internal\convert.d
- copy $** $@
+ copy $** $@
$(IMPDIR)\core\stdc\complex.d : src\core\stdc\complex.d
copy $** $@
diff --git a/win64.mak b/win64.mak
index db45aba1de8..6c93b32eed8 100644
--- a/win64.mak
+++ b/win64.mak
@@ -190,10 +190,10 @@ $(IMPDIR)\core\vararg.d : src\core\vararg.d
copy $** $@
$(IMPDIR)\core\internal\hash.d : src\core\internal\hash.d
- copy $** $@
+ copy $** $@
$(IMPDIR)\core\internal\convert.d : src\core\internal\convert.d
- copy $** $@
+ copy $** $@
$(IMPDIR)\core\stdc\complex.d : src\core\stdc\complex.d
copy $** $@