本文整理汇总了Golang中math.Signbit函数的典型用法代码示例。如果您正苦于以下问题:Golang Signbit函数的具体用法?Golang Signbit怎么用?Golang Signbit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Signbit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exitAxis
// exitAxis reports which axis the directed line L exits the cube face F on.
// The directed line L is represented by its CCW normal N in the (u,v,w) coordinates
// of F. It returns axisU if L exits through the u=-1 or u=+1 edge, and axisV if L exits
// through the v=-1 or v=+1 edge. Either result is acceptable if L exits exactly
// through a corner vertex of the cube face.
func (p pointUVW) exitAxis() axis {
if p.intersectsOppositeEdges() {
// The line passes through through opposite edges of the face.
// It exits through the v=+1 or v=-1 edge if the u-component of N has a
// larger absolute magnitude than the v-component.
if math.Abs(p.X) >= math.Abs(p.Y) {
return axisV
}
return axisU
}
// The line passes through through two adjacent edges of the face.
// It exits the v=+1 or v=-1 edge if an even number of the components of N
// are negative. We test this using signbit() rather than multiplication
// to avoid the possibility of underflow.
var x, y, z int
if math.Signbit(p.X) {
x = 1
}
if math.Signbit(p.Y) {
y = 1
}
if math.Signbit(p.Z) {
z = 1
}
if x^y^z == 0 {
return axisV
}
return axisU
}
示例2: opp
//'true' if opposite signs; false otherwise
func opp(x float64, y float64) bool {
if math.Signbit(x) == math.Signbit(y) {
return false
} else {
return true
}
}
示例3: randomSchurCanonical
// randomSchurCanonical returns a random, general matrix in Schur canonical
// form, that is, block upper triangular with 1×1 and 2×2 diagonal blocks where
// each 2×2 diagonal block has its diagonal elements equal and its off-diagonal
// elements of opposite sign.
func randomSchurCanonical(n, stride int, rnd *rand.Rand) blas64.General {
t := randomGeneral(n, n, stride, rnd)
// Zero out the lower triangle.
for i := 0; i < t.Rows; i++ {
for j := 0; j < i; j++ {
t.Data[i*t.Stride+j] = 0
}
}
// Randomly create 2×2 diagonal blocks.
for i := 0; i < t.Rows; {
if i == t.Rows-1 || rnd.Float64() < 0.5 {
// 1×1 block.
i++
continue
}
// 2×2 block.
// Diagonal elements equal.
t.Data[(i+1)*t.Stride+i+1] = t.Data[i*t.Stride+i]
// Off-diagonal elements of opposite sign.
c := rnd.NormFloat64()
if math.Signbit(c) == math.Signbit(t.Data[i*t.Stride+i+1]) {
c *= -1
}
t.Data[(i+1)*t.Stride+i] = c
i += 2
}
return t
}
示例4: sameValue
func sameValue(x Value, y Value) bool {
if x.kind != y.kind {
return false
}
result := false
switch x.kind {
case valueUndefined, valueNull:
result = true
case valueNumber:
x := x.float64()
y := y.float64()
if math.IsNaN(x) && math.IsNaN(y) {
result = true
} else {
result = x == y
if result && x == 0 {
// Since +0 != -0
result = math.Signbit(x) == math.Signbit(y)
}
}
case valueString:
result = x.string() == y.string()
case valueBoolean:
result = x.bool() == y.bool()
case valueObject:
result = x._object() == y._object()
default:
panic(hereBeDragons())
}
return result
}
示例5: VehicleKnockback
// Creates knockback for a vehicle
func (p *Physics) VehicleKnockback(vehicle *state.Vehicle, kbAngle, kbVelocity float64) {
// Get vehicle velocity vectors
vehAngleX, vehAngleY := splitComponent(vehicle.Angle)
vehVectorX := vehAngleX * vehicle.Velocity
vehVectorY := vehAngleY * vehicle.Velocity
// Get knockback velocity vectors
kbAngleX, kbAngleY := splitComponent(kbAngle)
kbVectorX := kbAngleX * kbVelocity
kbVectorY := kbAngleY * kbVelocity
// Combine vectors
vectorX := vehVectorX + kbVectorX
vectorY := vehVectorY + kbVectorY
vehVelocity := combineComponents(vectorX, vectorY)
// Calculate angle perpendicularity as a percent
angleFactor := math.Mod(math.Abs(vehicle.Angle-kbAngle+90), 180) / 90.0
// Set vehicle velocity
if math.Signbit(vehicle.Velocity) == math.Signbit(vehVelocity) {
vehicle.Velocity = -vehVelocity * angleFactor
} else {
vehicle.Velocity = vehVelocity * angleFactor
}
}
示例6: Predict
func (f *andFeature) Predict(e Example) float64 {
if !math.Signbit(f.f1.Predict(e)) && !math.Signbit(f.f2.Predict(e)) {
return 1.0
} else {
return -1.0
}
}
示例7: CombineClusters
// CombineClusters combines freshly found clusters with existing clusters.
//
// Algorithm:
// Run clustering and pick out the "Interesting" clusters.
// Compare all the Interesting clusters to all the existing relevant clusters,
// where "relevant" clusters are ones whose Hash/timestamp of the step
// exists in the current tile.
// Start with an empty "list".
// For each cluster:
// For each relevant existing cluster:
// Take the top 20 keys from the existing cluster and count how many appear
// in the cluster.
// If there are no matches then this is a new cluster, add it to the "list".
// If there are matches, possibly to multiple existing clusters, find the
// existing cluster with the most matches.
// Take the cluster (old/new) with the most members, or the best fit if
// they have the same number of matches.
// Return all the updated clusters.
func CombineClusters(freshSummaries, oldSummaries []*types.ClusterSummary) []*types.ClusterSummary {
ret := []*types.ClusterSummary{}
stillFresh := []*types.ClusterSummary{}
// If two cluster summaries have the same hash and same Regression direction
// then they are the same, merge them together.
for _, fresh := range freshSummaries {
for _, old := range oldSummaries {
if fresh.Hash == old.Hash && math.Signbit(fresh.StepFit.Regression) == math.Signbit(old.StepFit.Regression) {
old.Merge(fresh)
ret = append(ret, old)
break
}
}
stillFresh = append(stillFresh, fresh)
}
// Even if a summary has a different hash it might still be the same event if
// there is an overlap in the traces each summary contains.
for _, fresh := range stillFresh {
var bestMatch *types.ClusterSummary = nil
bestMatchHits := 0
for _, old := range oldSummaries {
hits := 0
for _, key := range util.AtMost(old.Keys, 20) {
if util.In(key, fresh.Keys) {
hits += 1
}
}
if hits > bestMatchHits {
bestMatchHits = hits
bestMatch = old
}
}
if bestMatch != nil {
keysLengthEqual := len(fresh.Keys) == len(bestMatch.Keys)
regressionInSameDirection := math.Signbit(fresh.StepFit.Regression) == math.Signbit(bestMatch.StepFit.Regression)
freshHasBetterFit := math.Abs(fresh.StepFit.Regression) > math.Abs(bestMatch.StepFit.Regression)
freshHasMoreKeys := len(fresh.Keys) > len(bestMatch.Keys)
if freshHasMoreKeys || (keysLengthEqual && regressionInSameDirection && freshHasBetterFit) {
fresh.Status = bestMatch.Status
fresh.Message = bestMatch.Message
fresh.ID = bestMatch.ID
fresh.Bugs = bestMatch.Bugs
ret = append(ret, fresh)
// Find the bestMatch in oldSummaries and replace it with fresh.
for i, oldBest := range oldSummaries {
if oldBest == bestMatch {
oldSummaries[i] = fresh
break
}
}
}
} else {
ret = append(ret, fresh)
}
}
return ret
}
示例8: alike
func alike(a, b float64) bool {
switch {
case math.IsNaN(a) && math.IsNaN(b):
return true
case a == b:
return math.Signbit(a) == math.Signbit(b)
}
return false
}
示例9: cAlike
func cAlike(a, b complex128) bool {
switch {
case IsNaN(a) && IsNaN(b):
return true
case a == b:
return math.Signbit(real(a)) == math.Signbit(real(b)) && math.Signbit(imag(a)) == math.Signbit(imag(b))
}
return false
}
示例10: AreDifferent
// AreDifferent(x, y) bekaves like x != y, but sees NaN() as equal to NaN()
func AreDifferent(x float64, y float64) bool {
if math.IsNaN(x) && math.IsNaN(y) {
return false
}
if x == y && math.Signbit(x) != math.Signbit(y) { // 0 != -0
return true
}
return x != y
}
示例11: EqualWithinULP
// EqualWithinULP returns true if a and b are equal to within
// the specified number of floating point units in the last place.
func EqualWithinULP(a, b float64, ulp uint) bool {
if a == b {
return true
}
if math.IsNaN(a) || math.IsNaN(b) {
return false
}
if math.Signbit(a) != math.Signbit(b) {
return math.Float64bits(math.Abs(a))+math.Float64bits(math.Abs(b)) <= uint64(ulp)
}
return ulpDiff(math.Float64bits(a), math.Float64bits(b)) <= uint64(ulp)
}
示例12: testPrefixBoundary
func testPrefixBoundary(t *testing.T, scales []float64, prefixes string, mode int, wrap func(string) string) {
var str, str1, str2, pre string
var flt, fabs, fnum float64
var err error
base := 1024.0
if mode == SI {
base = 1000.0
}
for _, sign := range []float64{-1, +1} {
for i, f := range scales {
// Round towards zero.
str = FormatPrefix(math.Nextafter(sign*f, sign*ninf), mode, -1)
flt, err = ParsePrefix(str, mode)
fabs = math.Abs(flt)
pre = string(prefixes[0])
if i > 0 {
pre = string(prefixes[i-1])
}
pre = wrap(pre)
str1, str2 = split(str)
fnum = math.Abs(atof(str1))
if i == 0 {
assert.True(t, 1.0*loThres <= fnum && fnum <= 1.0)
} else {
assert.True(t, base*loThres <= fnum && fnum <= base)
}
assert.Equal(t, pre, str2)
assert.True(t, f*loThres <= fabs && fabs <= f)
assert.Equal(t, math.Signbit(flt), math.Signbit(sign))
assert.Equal(t, nil, err)
// Round away from zero.
str = FormatPrefix(math.Nextafter(sign*f, sign*pinf), mode, -1)
flt, err = ParsePrefix(str, mode)
fabs = math.Abs(flt)
pre = wrap(string(prefixes[i]))
str1, str2 = split(str)
fnum = math.Abs(atof(str1))
assert.True(t, 1.0 <= fnum && fnum <= 1.0*hiThres)
assert.Equal(t, pre, str2)
assert.True(t, f <= fabs && fabs <= f*hiThres)
assert.Equal(t, math.Signbit(flt), math.Signbit(sign))
assert.Equal(t, nil, err)
}
}
}
示例13: numberOperator
func numberOperator(left, right tree.Result, f *xpFilt, op string) error {
lt, lOK := left.(tree.IsNum)
rt, rOK := right.(tree.IsNum)
if !lOK || !rOK {
return fmt.Errorf("Cannot convert data type to number")
}
ln, rn := lt.Num(), rt.Num()
switch op {
case "*":
f.ctx = ln * rn
case "div":
if rn != 0 {
f.ctx = ln / rn
} else {
if ln == 0 {
f.ctx = tree.Num(math.NaN())
} else {
if math.Signbit(float64(ln)) == math.Signbit(float64(rn)) {
f.ctx = tree.Num(math.Inf(1))
} else {
f.ctx = tree.Num(math.Inf(-1))
}
}
}
case "mod":
f.ctx = tree.Num(int(ln) % int(rn))
case "+":
f.ctx = ln + rn
case "-":
f.ctx = ln - rn
case "=":
f.ctx = tree.Bool(ln == rn)
case "!=":
f.ctx = tree.Bool(ln != rn)
case "<":
f.ctx = tree.Bool(ln < rn)
case "<=":
f.ctx = tree.Bool(ln <= rn)
case ">":
f.ctx = tree.Bool(ln > rn)
case ">=":
f.ctx = tree.Bool(ln >= rn)
}
return nil
}
示例14: float64ToIntExp
// convert float64 to int64 where f == i / 2^exp
func float64ToIntExp(f float64) (i int64, exp int) {
if f == 0 {
return 0, 0
}
isNegative := math.Signbit(f)
f = math.Abs(f)
machineEpsilon := math.Nextafter(1, 2) - 1
exp = 0
// really large float, bring down to within MaxInt64
for f > float64(math.MaxInt64) {
f /= 2
exp--
}
for !float64IsInt(f, machineEpsilon) {
f *= 2
exp++
}
if isNegative {
f *= -1
}
return int64(f), exp
}
示例15: genVolumeTable
func genVolumeTable() {
// 0/127 = -INFdB
// 63/127 = -14dB
// 127/127 = 0dB
for n := uint8(0); n <= 127; n++ {
db := MIDItoDB(n)
//fmt.Printf("\"%+5.1f\", // %d == %d\n", db, n, dBtoMIDI(db))
posdb := math.Abs(db)
// Represent as u16 in BCD:
bcd0 := uint16((posdb - math.Floor(posdb)) * 10)
bcd1 := uint16(((posdb / 10.0) - math.Floor(posdb/10.0)) * 10)
bcd2 := uint16(((posdb / 100.0) - math.Floor(posdb/100.0)) * 10)
var bcd3 uint16
if math.Signbit(db) {
bcd3 = 0x0F
} else {
bcd3 = 0x00
}
db10s := (bcd3 << 12) | (bcd2 << 8) | (bcd1 << 4) | bcd0
if math.IsInf(db, -1) {
db10s = math.MaxUint16
}
fmt.Printf("0x%04X, // %d\n", db10s, n)
}
}