当前位置: 首页>>代码示例>>Golang>>正文


Golang math.Signbit函数代码示例

本文整理汇总了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
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:36,代码来源:edgeutil.go

示例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
	}
}
开发者ID:philhofer,项目名称:vec,代码行数:8,代码来源:rootFind.go

示例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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:32,代码来源:general.go

示例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
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:32,代码来源:value.go

示例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
	}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:27,代码来源:physics.go

示例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
	}
}
开发者ID:dominiccooney,项目名称:blink-tools,代码行数:7,代码来源:ml.go

示例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
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:77,代码来源:alerting.go

示例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
}
开发者ID:kostyll,项目名称:gccpy,代码行数:9,代码来源:zerodivide.go

示例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
}
开发者ID:h8liu,项目名称:golang,代码行数:9,代码来源:cmath_test.go

示例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
}
开发者ID:JoarLeth,项目名称:mugo,代码行数:12,代码来源:util.go

示例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)
}
开发者ID:sbinet,项目名称:gonum-floats,代码行数:14,代码来源:floats.go

示例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)
		}
	}
}
开发者ID:dsnet,项目名称:golib,代码行数:50,代码来源:strconv_test.go

示例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
}
开发者ID:ChrisTrenkamp,项目名称:goxpath,代码行数:48,代码来源:operators.go

示例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
}
开发者ID:Richardphp,项目名称:noms,代码行数:26,代码来源:number_util.go

示例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)
	}
}
开发者ID:JamesDunne,项目名称:eminor2,代码行数:27,代码来源:main.go


注:本文中的math.Signbit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。