Beispiel #1
0
// binary
// 23 = 10111
// special case if n==0 then return empty slice
// panic if n<0
func Binary(n int64) (bin []int) {

	var s int64

	if n < 0 {
		panic("binary representation of number smaller than 0")
	} else if n == 0 {
		s = 0
	} else {
		s = int64(math.Logb(float64(n))) + 1
	}

	bin = make([]int, s)

	i := 0
	var m int64

	for n != 0 {
		m = n / 2
		//fmt.Println(i, n, m)
		if n != m*2 {
			bin[i] = 1
		}
		n = m
		i++
	}
	return
}
Beispiel #2
0
func (ti *TouchInfo) Name() string {
	if int(ti.TouchVal) > 0 {
		i := int(math.Logb(float64(ti.TouchVal)))
		if i < len(TouchList) {
			return TouchList[i]
		}
	}
	return "None"
}
Beispiel #3
0
func TestDictionaryDefaultSize(t *testing.T) {
	words := testMakeWordSlice(50)
	dict := NewDictionaryWords(words)

	expectedSize := int(math.Logb(float64(len(words))))

	if dict.Size() != expectedSize {
		t.Errorf("Size() == %d, want %d", dict.Size(), expectedSize)
	}
}
Beispiel #4
0
func NewDictionaryWords(words []string) *Dictionary {
	count := len(words)
	maxSize := int(math.Logb(float64(count)))

	dict := &Dictionary{
		words:   words,
		size:    maxSize,
		maxSize: maxSize,
		seed:    0,
	}

	return dict
}
Beispiel #5
0
func newOtfHeader(scalerType Tag, numTables uint16) *otfHeader {

	// http://www.opensource.apple.com/source/ICU/ICU-491.11.3/icuSources/layout/KernTable.cpp?txt
	entrySelector := uint16(math.Logb(float64(numTables)))
	searchRange := ((1 << entrySelector) * uint16(16))
	rangeShift := (numTables * uint16(16)) - searchRange

	return &otfHeader{
		ScalerType:    scalerType,
		NumTables:     numTables,
		EntrySelector: entrySelector,
		SearchRange:   searchRange,
		RangeShift:    rangeShift,
	}

}
Beispiel #6
0
func TestNewDictionaryWords(t *testing.T) {
	words := testMakeWordSlice(30)
	dict := NewDictionaryWords(words)

	if !testSlicesEqual(dict.words, words) {
		t.Error("dict.words != words")
	}

	expectedSize := int(math.Logb(float64(len(words))))
	if dict.size != expectedSize {
		t.Errorf("dict.size == %d, want %d", dict.size, expectedSize)
	}

	if dict.size != dict.maxSize {
		t.Error("dict.size != dict.maxSize")
	}
}
Beispiel #7
0
func (d *Dictionary) readIn(r io.Reader) {
	d.words = make([]string, 0, 1<<uint(d.size))

	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		if err := scanner.Err(); err != nil && err != io.EOF {
			break
		}

		d.words = append(d.words, scanner.Text())
	}

	count := len(d.words)
	d.maxSize = int(math.Logb(float64(count)))

	d.size = d.maxSize
}
Beispiel #8
0
// float32 version of math.Logbf
func Logb(x float32) float32 {
	return float32(math.Logb(float64(x)))
}
func calculateMaxBackoffCount(maxDuration time.Duration) int {
	total := math.Ceil(float64(maxDuration) / float64(CrashBackoffMinDuration))
	return int(math.Logb(total))
}