github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/util/convert.go (about)

     1  package util
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  )
     7  
     8  // util/SmallFloat.java
     9  // Floating point numbers smaller than 32 bits.
    10  
    11  /** byteToFloat(b, mantissaBits=3, zeroExponent=15) */
    12  func Byte315ToFloat(b byte) float32 {
    13  	// on Java1.5 & 1.6 JVMs, prebuilding a decoding array and doing a lookup
    14  	// is only a little bit faster (anywhere from 0% to 7%)
    15  	// However, is it faster for Go? TODO need benchmark
    16  	if b == 0 {
    17  		return 0
    18  	}
    19  	bits := uint32(b) << (24 - 3)
    20  	bits += (63 - 15) << 24
    21  	return math.Float32frombits(bits)
    22  }
    23  
    24  func ItoHex(i int64) string {
    25  	return strconv.FormatInt(i, 16)
    26  }