1 /* go-type-complex.c -- hash and equality complex functions.
3 Copyright 2012 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
14 /* Hash function for float types. */
17 __go_type_hash_complex (const void *vkey
, uintptr_t key_size
)
21 const complex float *cfp
;
27 cfp
= (const complex float *) vkey
;
33 if (isinf (cfr
) || isinf (cfi
))
36 /* NaN != NaN, so the hash code of a NaN is irrelevant. Make it
37 random so that not all NaNs wind up in the same place. */
38 if (isnan (cfr
) || isnan (cfi
))
39 return runtime_fastrand1 ();
41 /* Avoid negative zero. */
42 if (cfr
== 0 && cfi
== 0)
50 return (uintptr_t) cfi
;
52 else if (key_size
== 16)
54 const complex double *cdp
;
60 cdp
= (const complex double *) vkey
;
66 if (isinf (cdr
) || isinf (cdi
))
69 if (isnan (cdr
) || isnan (cdi
))
70 return runtime_fastrand1 ();
72 /* Avoid negative zero. */
73 if (cdr
== 0 && cdi
== 0)
80 memcpy (&di
, &cd
, 16);
84 runtime_throw ("__go_type_hash_complex: invalid complex size");
87 const FuncVal __go_type_hash_complex_descriptor
=
88 { (void *) __go_type_hash_complex
};
90 /* Equality function for complex types. */
93 __go_type_equal_complex (const void *vk1
, const void *vk2
, uintptr_t key_size
)
97 const complex float *cfp1
;
98 const complex float *cfp2
;
100 cfp1
= (const complex float *) vk1
;
101 cfp2
= (const complex float *) vk2
;
103 return *cfp1
== *cfp2
;
105 else if (key_size
== 16)
107 const complex double *cdp1
;
108 const complex double *cdp2
;
110 cdp1
= (const complex double *) vk1
;
111 cdp2
= (const complex double *) vk2
;
113 return *cdp1
== *cdp2
;
116 runtime_throw ("__go_type_equal_complex: invalid complex size");
119 const FuncVal __go_type_equal_complex_descriptor
=
120 { (void *) __go_type_equal_complex
};