1 /* go-type-float.c -- hash and equality float 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. */
12 /* Hash function for float types. */
15 __go_type_hash_float (const void *vkey
, uintptr_t key_size
)
23 fp
= (const float *) vkey
;
26 if (isinf (f
) || f
== 0)
29 /* NaN != NaN, so the hash code of a NaN is irrelevant. Make it
30 random so that not all NaNs wind up in the same place. */
32 return runtime_fastrand1 ();
34 memcpy (&si
, vkey
, 4);
35 return (uintptr_t) si
;
37 else if (key_size
== 8)
43 dp
= (const double *) vkey
;
46 if (isinf (d
) || d
== 0)
50 return runtime_fastrand1 ();
52 memcpy (&di
, vkey
, 8);
53 return (uintptr_t) di
;
56 runtime_throw ("__go_type_hash_float: invalid float size");
59 /* Equality function for float types. */
62 __go_type_equal_float (const void *vk1
, const void *vk2
, uintptr_t key_size
)
69 fp1
= (const float *) vk1
;
70 fp2
= (const float *) vk2
;
74 else if (key_size
== 8)
79 dp1
= (const double *) vk1
;
80 dp2
= (const double *) vk2
;
85 runtime_throw ("__go_type_equal_float: invalid float size");