1 /*
2  *  Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com
3  *  Written by Walter Bright
4  *
5  *  This software is provided 'as-is', without any express or implied
6  *  warranty. In no event will the authors be held liable for any damages
7  *  arising from the use of this software.
8  *
9  *  Permission is granted to anyone to use this software for any purpose,
10  *  including commercial applications, and to alter it and redistribute it
11  *  freely, in both source and binary form, subject to the following
12  *  restrictions:
13  *
14  *  o  The origin of this software must not be misrepresented; you must not
15  *     claim that you wrote the original software. If you use this software
16  *     in a product, an acknowledgment in the product documentation would be
17  *     appreciated but is not required.
18  *  o  Altered source versions must be plainly marked as such, and must not
19  *     be misrepresented as being the original software.
20  *  o  This notice may not be removed or altered from any source
21  *     distribution.
22  */
23 
24 module rt.compiler.gdc.typeinfo.ti_Adouble;
25 
26 private import rt.compiler.gdc.typeinfo.ti_double;
27 private import rt.compiler.util.hash;
28 
29 // double[]
30 
31 class TypeInfo_Ad : TypeInfo_Array
32 {
33     override char[] toString() { return "double[]"; }
34 
35     override hash_t getHash(in void* p){
36         double[] s = *cast(double[]*)p;
37         size_t len = s.length;
38         auto str = s.ptr;
39         return rt_hash_str(str,len*double.sizeof,0); // use rt_hash_block?
40     }
41 
42     override equals_t equals(in void* p1, in void* p2)
43     {
44         double[] s1 = *cast(double[]*)p1;
45         double[] s2 = *cast(double[]*)p2;
46         size_t len = s1.length;
47 
48         if (len != s2.length)
49             return 0;
50         for (size_t u = 0; u < len; u++)
51         {
52             if (!TypeInfo_d._equals(s1[u], s2[u]))
53                 return false;
54         }
55         return true;
56     }
57 
58     override int compare(in void* p1, in void* p2)
59     {
60         double[] s1 = *cast(double[]*)p1;
61         double[] s2 = *cast(double[]*)p2;
62         size_t len = s1.length;
63 
64         if (s2.length < len)
65             len = s2.length;
66         for (size_t u = 0; u < len; u++)
67         {
68             int c = TypeInfo_d._compare(s1[u], s2[u]);
69             if (c)
70                 return c;
71         }
72         if (s1.length < s2.length)
73             return -1;
74         else if (s1.length > s2.length)
75             return 1;
76         return 0;
77     }
78 
79     override size_t talign()
80     {
81         return (double[]).alignof;
82     }
83 
84     override size_t tsize()
85     {
86         return (double[]).sizeof;
87     }
88 
89     override uint flags()
90     {
91         return 1;
92     }
93 
94     override TypeInfo next()
95     {
96         return typeid(double);
97     }
98 
99     version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
100     {
101         return 0;
102     }
103 }
104 
105 // idouble[]
106 
107 class TypeInfo_Ap : TypeInfo_Ad
108 {
109     char[] toString() { return "idouble[]"; }
110 
111     override TypeInfo next()
112     {
113         return typeid(idouble);
114     }
115 }