mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 04:23:41 +00:00
src/runtime: improve float/complex hashing
This allows positive and negative zero to hash to the same value, as required by Go. This is not perfect, but the best I could do without revamping all the hash funtions to take a seed. Fixes #2356
This commit is contained in:
Vendored
+45
-1
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "sort"
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
var testmap1 = map[string]int{"data": 3}
|
||||
var testmap2 = map[string]int{
|
||||
@@ -109,6 +111,48 @@ func main() {
|
||||
squares = make(map[int]int, 20)
|
||||
testBigMap(squares, 40)
|
||||
println("tested growing of a map")
|
||||
|
||||
floatcmplx()
|
||||
}
|
||||
|
||||
func floatcmplx() {
|
||||
|
||||
var zero float64
|
||||
var negz float64 = -zero
|
||||
|
||||
// test that zero and negative zero hash to the same thing
|
||||
m := make(map[float64]int)
|
||||
m[zero]++
|
||||
m[negz]++
|
||||
println(m[negz])
|
||||
|
||||
cmap := make(map[complex128]int)
|
||||
|
||||
var c complex128
|
||||
c = complex(zero, zero)
|
||||
cmap[c]++
|
||||
|
||||
c = complex(negz, negz)
|
||||
cmap[c]++
|
||||
|
||||
c = complex(0, 0)
|
||||
println(cmap[c])
|
||||
|
||||
c = complex(1, negz)
|
||||
cmap[c]++
|
||||
|
||||
c = complex(1, zero)
|
||||
cmap[c]++
|
||||
|
||||
println(cmap[c])
|
||||
|
||||
c = complex(negz, 2)
|
||||
cmap[c]++
|
||||
|
||||
c = complex(zero, 2)
|
||||
cmap[c]++
|
||||
|
||||
println(cmap[c])
|
||||
}
|
||||
|
||||
func readMap(m map[string]int, key string) {
|
||||
|
||||
Vendored
+4
@@ -72,3 +72,7 @@ structMap[{"tau", 3.14}]: 0
|
||||
structMap[{"tau", 6.28}]: 0
|
||||
tested preallocated map
|
||||
tested growing of a map
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
|
||||
Reference in New Issue
Block a user