Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float64 optimization #193

Open
brainswa opened this issue Dec 14, 2024 · 0 comments
Open

Float64 optimization #193

brainswa opened this issue Dec 14, 2024 · 0 comments

Comments

@brainswa
Copy link

func (z *Int) Float64() float64 {
  var bitlen uint64
  switch {
  case z[3] != 0:
    bitlen = uint64(bits.Len64(z[3])) - 1
    return math.Float64frombits((1023+192+bitlen)<<52 | ((z[3]<<(64-bitlen))|(z[2]>>bitlen))>>12)
  case z[2] != 0:
    bitlen = uint64(bits.Len64(z[2])) - 1
    return math.Float64frombits((1023+128+bitlen)<<52 | ((z[2]<<(64-bitlen))|(z[1]>>bitlen))>>12)
  case z[1] != 0:
    bitlen = uint64(bits.Len64(z[1])) - 1
    return math.Float64frombits((1023+64+bitlen)<<52 | ((z[1]<<(64-bitlen))|(z[0]>>bitlen))>>12)
  default:
    return float64(z[0])
  }
}
BenchmarkFloat64
BenchmarkFloat64-8       	337167862	         3.267 ns/op
BenchmarkFloat64Fast
BenchmarkFloat64Fast-8   	737007931	         1.708 ns/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant