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 /* Equality function for complex types. */
90 __go_type_equal_complex (const void *vk1
, const void *vk2
, uintptr_t key_size
)
94 const complex float *cfp1
;
95 const complex float *cfp2
;
97 cfp1
= (const complex float *) vk1
;
98 cfp2
= (const complex float *) vk2
;
100 return *cfp1
== *cfp2
;
102 else if (key_size
== 16)
104 const complex double *cdp1
;
105 const complex double *cdp2
;
107 cdp1
= (const complex double *) vk1
;
108 cdp2
= (const complex double *) vk2
;
110 return *cdp1
== *cdp2
;
113 runtime_throw ("__go_type_equal_complex: invalid complex size");