本文整理汇总了Golang中math.Exp2函数的典型用法代码示例。如果您正苦于以下问题:Golang Exp2函数的具体用法?Golang Exp2怎么用?Golang Exp2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Exp2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: expTables
// expTables prepares the exp-tables described in section 6.4 of the EIDMA report by F.M.J. Willems and Tj. J. Tjalkens.
// Complexity Reduction of the Context-Tree Weighting Algorithm: A Study for KPN Research, Technical University of Eindhoven, EIDMA Report RS.97.01
func expTables() ([]uint64, []uint64) {
var pow2f float64 = 1 << f
A := make([]uint64, int(pow2f)+1)
for i := 1; i <= int(pow2f); i++ {
A[i] = uint64(pow2f*math.Exp2(-float64(i)/pow2f) + 0.5)
}
// B entries for (1<<(f-1)), (1<<f)-1
B := make([]uint64, int(pow2f))
for j := 1 << (f - 1); j <= (1<<f)-1; j++ {
B[j] = uint64(-pow2f*math.Log2(float64(j)/pow2f) + 0.5)
}
// B entries for 1,(1<<(f-1))-1
for j := 1; j < (1 << (f - 1)); j++ {
k := math.Ceil(float64(f) - 1 - math.Log2(float64(j)))
b2kj := B[int(math.Exp2(k))*j]
if b2kj == 0 {
panic("")
}
B[j] = b2kj + uint64(k*pow2f)
}
return A, B
}
示例2: main
func main() {
var err error
workerCount, err = strconv.Atoi(os.Getenv("GOMAXPROCS"))
if err != nil {
workerCount = 1
}
var nClauses, nVar int
fmt.Scanf("%d %d", &nClauses, &nVar)
clauses := readClauses(nClauses, nVar)
startTime := time.Now()
solution := solveClauses(clauses, nClauses, nVar)
if solution >= 0 {
fmt.Printf("Solution found [%d]: ", solution)
for i := 0; i < nVar; i++ {
fmt.Printf("%d ", int64(float64(solution&int64(math.Exp2(float64(i))))/math.Exp2(float64(i))))
}
fmt.Printf("\n")
} else {
fmt.Printf("Solution not found.\n")
}
duration := time.Since(startTime)
fmt.Println("Duration: ", duration)
}
示例3: solveClauses
func solveClauses(clauses [][]int8, nClauses, nVar int) int64 {
iVar = make([]int64, nVar)
for i := 0; i < nVar; i++ {
iVar[i] = int64(math.Exp2(float64(i)))
}
maxNumber = int64(math.Exp2(float64(nVar)))
ch := make(chan int64)
for i := 0; i < workerCount; i++ {
go clauseSolverWorker(clauses, nClauses, i, ch)
}
var solution int64 = -1
for i := 0; i < workerCount; i++ {
solution = <-ch
if solution < 0 {
continue
} else {
fmt.Println(solution)
break
}
}
return solution
}
示例4: rgamma2
// Random gamma variable when shape<1
// See Kundu and Gupta 2007
// "A convenient way of generating gamma random variables using generalized exponential distribution"
func (rg RandGen) rgamma2(shape float64) float64 {
if shape <= 0.0 || shape >= 1.0 {
panic("Illegal parameter. Shape must be positive and no greater than one")
}
d := 1.0334 - 0.0766*math.Exp(2.2942*shape) // Constants from paper
a := math.Exp2(shape) * math.Pow(-math.Expm1(-d/2), shape)
pdsh := math.Pow(d, shape-1.0)
b := shape * pdsh * math.Exp(-d)
c := a + b
start:
u := rg.Float64()
var x float64
if u <= a/c {
x = -2.0 * math.Log1p(-math.Pow(c*u, 1.0/shape)/2.0)
} else {
x = -math.Log(c * (1.0 - u) / (shape * pdsh))
}
v := rg.Float64()
if x <= d {
p := math.Pow(x, shape-1.0) * math.Exp(-x/2.0) / (math.Exp2(shape-1.0) * math.Pow(-math.Expm1(-x/2.0), shape-1.0))
if v > p {
goto start
}
} else {
if v > math.Pow(d/x, 1.0-shape) {
goto start
}
}
return x
}
示例5: errorWithPrecision
// errorWithPrecision returns the error range in latitude and longitude for in
// integer geohash with bits of precision.
func errorWithPrecision(bits uint) (latErr, lngErr float64) {
latBits := bits / 2
lngBits := bits - latBits
latErr = 180.0 / math.Exp2(float64(latBits))
lngErr = 360.0 / math.Exp2(float64(lngBits))
return
}
示例6: next
func (s *song) next() (n int, freq float64) {
if len(s.tones) == 0 {
s.last = s.center
return 1, s.last
}
cSum, ampSum := s.partialComplexity()
sum := 0.0
sums := make([]float64, len(rats))
for i, r := range rats {
p := math.Log2(s.last * r.float() / s.center)
sum += math.Exp2(-p*p/2) * math.Exp2(-s.complexityWith(cSum, ampSum, r))
sums[i] = sum
}
i := 0
x := sum * rand.Float64()
for i = range sums {
if x < sums[i] {
break
}
}
r := rats[i]
s.last *= r.float()
r.a *= s.tones[len(s.tones)-1].n
for _, t := range s.tones {
t.n *= r.b
}
return r.a, s.last
}
示例7: newFrequency
func (m *Melody) newFrequency() ratio {
harmonies := make([]int, len(m.history))
for i, n := range m.history {
harmonies[i] = n.f
}
return selectRatio(func(r ratio) float64 {
dp := math.Log2(m.lastFrequency * r.float() / m.avgFrequency)
return math.Exp2(-dp*dp/2) * math.Exp2(m.frequencyBias*m.frequencyComplexity(harmonies, r))
})
}
示例8: digitsSignature
func digitsSignature(n int) int {
r := 0
for n != 0 {
d := n - (n/10)*10
if (r & int(math.Exp2(float64(d)))) == 0 {
r += int(math.Exp2(float64(d)))
}
n = (n - d) / 10
}
return r
}
示例9: partialComplexity
func (s *song) partialComplexity() (cSum, ampSum float64) {
for _, t1 := range s.tones {
a1 := math.Exp2(t1.amp)
for _, t2 := range s.tones {
a2 := math.Exp2(t2.amp)
cSum += a1 * a2 * float64(complexity(t1.n, t2.n))
}
ampSum += a1
}
return
}
示例10: Sing
func (v *voice) Sing() float64 {
p := math.Exp2(v.Pitch.Sing())
r := math.Exp2(v.Amp.Sing()) * v.rand.NormFloat64()
if v.Pitch.Done() && v.Amp.Done() {
r = 0
}
c := v.b*v.b/4 + 4*math.Pi*math.Pi*p*p
v.u += v.dt*v.v + v.sqdt*r
v.v -= v.dt * (v.b*v.v + c*v.u)
v.RMS.Add(v.u)
return v.u
}
示例11: decay
// Given the time stamp, decay the scores
func (ts *territoryScore) decay(now *time.Time) {
// The decay is based on an exponential half time
deltaTime := float64(now.Sub(ts.TimeStamp))
ts.TimeStamp = *now
ts.modified = true
// Update decay of Score
ts.Score *= math.Exp2(-deltaTime / float64(ConfigScoreHalfLife))
// Update the decay of ScoreBalance. Subtract the offset before doing the decay, and add it
// back again afterwards.
bal := ts.ScoreBalance - ConfigScoreBalanceZero
ts.ScoreBalance = bal*math.Exp2(-deltaTime/float64(ConfigScoreBalHalfLife)) + ConfigScoreBalanceZero
}
示例12: encodeHead2
func (this *defCodec) encodeHead2(b []byte) {
if ln := len(b) - 2; ln <= (int(math.Exp2(16))-1) && ln <= this.maxPacketSize {
this.byteOrder.PutUint16(b, uint16(ln))
} else {
panic(ErrCodecTooLarge)
}
}
示例13: Add
// add two numbers without using arithmetic operators
func Add(x, y uint32) uint32 {
var answer uint32
var carry bool
// function to return either 0 or 1, the bit of `num` at `position`
for i := 0; i < 32; i++ {
var b uint32 = uint32(math.Exp2(float64(i))) // need to do some casting and this syntax is likely wrong
if (b&x)&(b&y) > 0 {
if carry == true {
answer = answer | b
}
carry = true
} else if (b&x)|(b&y) > 0 {
if carry == false {
answer = answer | b
}
} else {
if carry == true {
answer = answer | b
}
carry = false
}
}
return answer
}
示例14: calculateVanityAddressStuff
func calculateVanityAddressStuff(vad VanityAddressData) VanityAddressData {
answer := vad
var complexity float64 = 1.0
var lavishness float64 = 1.0
var bounty float64 = answer.Bounty
pattern := answer.Pattern[1:]
countingOnes := true
for i := 0; i < len(pattern); i++ {
if countingOnes {
if pattern[i] == '1' {
complexity *= 256
} else {
complexity *= 58
countingOnes = false
}
} else {
complexity *= 58
}
}
lavishness = math.Exp2(32.0) * bounty / complexity
answer.Complexity = complexity
answer.Lavishness = lavishness
answer.ComplexityStr = fmt.Sprintf("%g", complexity)
answer.LavishnessStr = fmt.Sprintf("%g", lavishness)
answer.BountyStr = fmt.Sprintf("%.8g", bounty)
return answer
}
示例15: hashIt
//Hash function for IP:Port, Key and Rel
func hashIt(s string, bit int) int {
h := sha1.New()
h.Write([]byte(s))
bs := h.Sum(nil)
hashValue := math.Mod(float64(bs[len(bs)-1]), math.Exp2(float64(bit)))
return int(hashValue)
}