/src/rt/typeinfo/ti_Adouble.d
D | 96 lines | 66 code | 16 blank | 14 comment | 10 complexity | c5a162a23bad3ce737b9a41158743279 MD5 | raw file
1/** 2 * TypeInfo support code. 3 * 4 * Copyright: Copyright Digital Mars 2004 - 2009. 5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 6 * Authors: Walter Bright 7 */ 8 9/* Copyright Digital Mars 2004 - 2009. 10 * Distributed under the Boost Software License, Version 1.0. 11 * (See accompanying file LICENSE or copy at 12 * http://www.boost.org/LICENSE_1_0.txt) 13 */ 14module rt.typeinfo.ti_Adouble; 15 16private import rt.typeinfo.ti_double; 17private import rt.util.hash; 18 19// double[] 20 21class TypeInfo_Ad : TypeInfo_Array 22{ 23 override bool opEquals(Object o) { return TypeInfo.opEquals(o); } 24 25 @trusted: 26 const: 27 pure: 28 nothrow: 29 30 override string toString() const pure nothrow @safe { return "double[]"; } 31 32 override size_t getHash(in void* p) 33 { 34 double[] s = *cast(double[]*)p; 35 return hashOf(s.ptr, s.length * double.sizeof); 36 } 37 38 override bool equals(in void* p1, in void* p2) 39 { 40 double[] s1 = *cast(double[]*)p1; 41 double[] s2 = *cast(double[]*)p2; 42 size_t len = s1.length; 43 44 if (len != s2.length) 45 return 0; 46 for (size_t u = 0; u < len; u++) 47 { 48 if (!TypeInfo_d._equals(s1[u], s2[u])) 49 return false; 50 } 51 return true; 52 } 53 54 override int compare(in void* p1, in void* p2) 55 { 56 double[] s1 = *cast(double[]*)p1; 57 double[] s2 = *cast(double[]*)p2; 58 size_t len = s1.length; 59 60 if (s2.length < len) 61 len = s2.length; 62 for (size_t u = 0; u < len; u++) 63 { 64 int c = TypeInfo_d._compare(s1[u], s2[u]); 65 if (c) 66 return c; 67 } 68 if (s1.length < s2.length) 69 return -1; 70 else if (s1.length > s2.length) 71 return 1; 72 return 0; 73 } 74 75 override @property const(TypeInfo) next() nothrow pure 76 { 77 return typeid(double); 78 } 79} 80 81// idouble[] 82 83class TypeInfo_Ap : TypeInfo_Ad 84{ 85 @trusted: 86 const: 87 pure: 88 nothrow: 89 90 override string toString() const pure nothrow @safe { return "idouble[]"; } 91 92 override @property const(TypeInfo) next() nothrow pure 93 { 94 return typeid(idouble); 95 } 96}