1 2 // double 3 4 module rt.compiler.gdc.typeinfo.ti_double; 5 private import rt.compiler.util.hash; 6 7 class TypeInfo_d : TypeInfo 8 { 9 override char[] toString() { return "double"; } 10 11 override hash_t getHash(in void* p) 12 { 13 return rt_hash_str(p,double.sizeof); 14 } 15 16 static equals_t _equals(double f1, double f2) 17 { 18 return f1 == f2 || 19 (f1 !<>= f1 && f2 !<>= f2); 20 } 21 22 static int _compare(double d1, double d2) 23 { 24 if (d1 !<>= d2) // if either are NaN 25 { 26 if (d1 !<>= d1) 27 { if (d2 !<>= d2) 28 return 0; 29 return -1; 30 } 31 return 1; 32 } 33 return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); 34 } 35 36 override equals_t equals(in void* p1, in void* p2) 37 { 38 return _equals(*cast(double *)p1, *cast(double *)p2); 39 } 40 41 override int compare(in void* p1, in void* p2) 42 { 43 return _compare(*cast(double *)p1, *cast(double *)p2); 44 } 45 46 override size_t talign() 47 { 48 return double.alignof; 49 } 50 51 override size_t tsize() 52 { 53 return double.sizeof; 54 } 55 56 override void swap(void *p1, void *p2) 57 { 58 double t; 59 60 t = *cast(double *)p1; 61 *cast(double *)p1 = *cast(double *)p2; 62 *cast(double *)p2 = t; 63 } 64 65 override void[] init() 66 { static double r; 67 68 return (cast(double *)&r)[0 .. 1]; 69 } 70 }