當前位置: 首頁>>代碼示例>>Golang>>正文


Golang math.IsNaN函數代碼示例

本文整理匯總了Golang中math.IsNaN函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsNaN函數的具體用法?Golang IsNaN怎麽用?Golang IsNaN使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IsNaN函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRunSeries

func TestRunSeries(z *testing.T) {
	assert := assert.New(z)
	var assertFloat = func(a, b float64) {
		if math.IsNaN(a) && math.IsNaN(b) {
			return // ok
		}
		assert.Equal(a, b)
	}

	tests := []Series{
		{1, 2, 3, 4, 5},
		{0.38809179, 0.94113008, 0.15350705, 0.03311646, 0.68168087, 0.21719990},
		{0.32123922, 0.57085251, 0.53576882, 0.38965630, 0.27487263, 0.90783122},
		{0, 0, 0, 0, 0},
		{-1, -2, -3},
		{},
	}

	for _, t := range tests {
		var r Run
		for _, f := range t {
			r.Add(f)
		}

		assertFloat(t.Min(), r.Min())
		assertFloat(t.Max(), r.Max())
		assertFloat(t.Mean(), r.Mean())
		assertFloat(t.Var(), r.Var())
		assertFloat(t.Std(), r.Std())
		assertFloat(t.VarP(), r.VarP())
		assertFloat(t.StdP(), r.StdP())
	}
}
開發者ID:goulash,項目名稱:stat,代碼行數:33,代碼來源:run_test.go

示例2: calculateLessThan

func calculateLessThan(left Value, right Value, leftFirst bool) _lessThanResult {

	x := Value{}
	y := x

	if leftFirst {
		x = toNumberPrimitive(left)
		y = toNumberPrimitive(right)
	} else {
		y = toNumberPrimitive(right)
		x = toNumberPrimitive(left)
	}

	result := false
	if x.kind != valueString || y.kind != valueString {
		x, y := x.float64(), y.float64()
		if math.IsNaN(x) || math.IsNaN(y) {
			return lessThanUndefined
		}
		result = x < y
	} else {
		x, y := x.string(), y.string()
		result = x < y
	}

	if result {
		return lessThanTrue
	}

	return lessThanFalse
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:31,代碼來源:evaluate.go

示例3: strictEqualityComparison

func strictEqualityComparison(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 = false
		} else {
			result = x == 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,代碼行數:28,代碼來源:value.go

示例4: GenericBoxes

// GenericBoxes draws box plots. (Default implementation for box plots).
// The values for each box in boxes are in screen coordinates!
func GenericBoxes(bg BasicGraphics, boxes []Box, width int, style Style) {
	if width%2 == 0 {
		width += 1
	}
	hbw := (width - 1) / 2
	for _, d := range boxes {
		x := int(d.X)
		q1, q3 := int(d.Q1), int(d.Q3)
		// DebugLogger.Printf("q1=%d  q3=%d  q3-q1=%d", q1,q3,q3-q1)
		bg.Rect(x-hbw, q1, width, q3-q1, style)
		if !math.IsNaN(d.Med) {
			med := int(d.Med)
			bg.Line(x-hbw, med, x+hbw, med, style)
		}

		if !math.IsNaN(d.Avg) {
			bg.Symbol(x, int(d.Avg), style)
		}

		if !math.IsNaN(d.High) {
			bg.Line(x, q3, x, int(d.High), style)
		}

		if !math.IsNaN(d.Low) {
			bg.Line(x, q1, x, int(d.Low), style)
		}

		for _, y := range d.Outliers {
			bg.Symbol(x, int(y), style)
		}

	}

}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:36,代碼來源:graphics.go

示例5: Compare

// Compare implements the Datum interface.
func (d *DFloat) Compare(other Datum) int {
	if other == DNull {
		// NULL is less than any non-NULL value.
		return 1
	}
	v, ok := other.(*DFloat)
	if !ok {
		cmp, ok := mixedTypeCompare(d, other)
		if !ok {
			panic(makeUnsupportedComparisonMessage(d, other))
		}
		return cmp
	}
	if *d < *v {
		return -1
	}
	if *d > *v {
		return 1
	}
	// NaN sorts before non-NaN (#10109).
	if *d == *v {
		return 0
	}
	if math.IsNaN(float64(*d)) {
		if math.IsNaN(float64(*v)) {
			return 0
		}
		return -1
	}
	return 1
}
開發者ID:nvanbenschoten,項目名稱:cockroach,代碼行數:32,代碼來源:datum.go

示例6: PixelDistance

func PixelDistance(image image.Image, x, y int, r, g, b, a uint32) float64 {
	if x < image.Bounds().Min.X ||
		y < image.Bounds().Min.Y ||
		x > image.Bounds().Max.X ||
		y > image.Bounds().Max.Y {
		log.Printf("Invalid pixel at %d, %d", x, y)
		return 0.0
	}

	targetR, targetG, targetB, targetA := image.At(x, y).RGBA()

	distance := 0.0
	distance += math.Pow(float64(r-targetR), 2)
	if math.IsNaN(distance) {
		log.Printf("Distance is NaN after red at %d, %d", x, y)
	}
	distance += math.Pow(float64(g-targetG), 2)
	if math.IsNaN(distance) {
		log.Printf("Distance is NaN after green at %d, %d", x, y)
	}
	distance += math.Pow(float64(b-targetB), 2)
	if math.IsNaN(distance) {
		log.Printf("Distance is NaN after blue at %d, %d", x, y)
	}
	distance += math.Pow(float64(a-targetA), 2)
	if math.IsNaN(distance) {
		log.Printf("Distance is NaN after alpha at %d, %d", x, y)
	}
	distance = math.Sqrt(distance)
	if math.IsNaN(distance) {
		log.Printf("Distance is NaN after sqrt at %d, %d", x, y)
	}

	return distance
}
開發者ID:nlefler,項目名稱:VictoryBoogieWoogie,代碼行數:35,代碼來源:boogie.go

示例7: Push

func (w *Windowed) Push(n float64) {
	old := w.data[w.head]

	w.length++

	w.data[w.head] = n
	w.head++
	if w.head >= len(w.data) {
		w.head = 0
	}

	if !math.IsNaN(old) {
		w.sum -= old
		w.sumsq -= (old * old)
	} else {
		w.nans--
	}

	if !math.IsNaN(n) {
		w.sum += n
		w.sumsq += (n * n)
	} else {
		w.nans++
	}
}
開發者ID:tsheasha,項目名稱:carbonapi,代碼行數:25,代碼來源:expr.go

示例8: noNaN

func noNaN(v data.Vector, pol int) data.Vector {
	if math.IsNaN(v[X]) || math.IsNaN(v[Y]) || math.IsNaN(v[Z]) {
		return data.Vector{0, 0, float64(pol)}
	} else {
		return v
	}
}
開發者ID:kyeongdong,項目名稱:3,代碼行數:7,代碼來源:config.go

示例9: Pearson

func Pearson(a, b []float64) float64 {

	if len(a) != len(b) {
		panic("len(a) != len(b)")
	}

	var abar, bbar float64
	var n int
	for i := range a {
		if !math.IsNaN(a[i]) && !math.IsNaN(b[i]) {
			abar += a[i]
			bbar += b[i]
			n++
		}
	}
	nf := float64(n)
	abar, bbar = abar/nf, bbar/nf

	var numerator float64
	var sumAA, sumBB float64

	for i := range a {
		if !math.IsNaN(a[i]) && !math.IsNaN(b[i]) {
			numerator += (a[i] - abar) * (b[i] - bbar)
			sumAA += (a[i] - abar) * (a[i] - abar)
			sumBB += (b[i] - bbar) * (b[i] - bbar)
		}
	}

	return numerator / (math.Sqrt(sumAA) * math.Sqrt(sumBB))
}
開發者ID:nnuss,項目名稱:go-onlinestats,代碼行數:31,代碼來源:pearson.go

示例10: Equal

func (o Sfloat64) Equal(n Any) bool {
	m := n.(Sfloat64)
	if math.IsNaN(float64(o)) && math.IsNaN(float64(m)) {
		return false
	}
	return o == m
}
開發者ID:andydude,項目名稱:droscheme,代碼行數:7,代碼來源:num.go

示例11: TestAbs

func TestAbs(result, expected, absolute_error float64, test_description string) (status int) {
	switch {
	case math.IsNaN(result) || math.IsNaN(expected):
		status = NaN

	case math.IsInf(result, 0) || math.IsInf(expected, 0):
		status = Inf

	case (expected > 0 && expected < DBL_MIN) || (expected < 0 && expected > -DBL_MIN):
		status = NotEqual

	default:
		if math.Abs(result-expected) > absolute_error {
			status = NotEqual
		} else {
			status = Equal
		}
	}
	if test_description != "" {
		io.Pf(test_description)
		switch status {
		case NaN:
			io.Pf(" [1;31mNaN[0m\n  %v observed\n  %v expected.  diff = %v\n", result, expected, result-expected)
		case Inf:
			io.Pf(" [1;31mInf[0m\n  %v observed\n  %v expected.  diff = %v\n", result, expected, result-expected)
		case Equal:
			io.Pf(" [1;32mOk[0m\n  %v observed\n  %v expected.  diff = %v\n", result, expected, result-expected)
		case NotEqual:
			io.Pf(" [1;31mError[0m\n  %v observed\n  %v expected.  diff = %v\n", result, expected, result-expected)
		}
	}
	return
}
開發者ID:yunpeng1,項目名稱:gosl,代碼行數:33,代碼來源:auxiliary.go

示例12: PrioritizeWorkUnits

// PrioritizeWorkUnits changes the priorities of some number of work
// units.  The actual work units are in options["work_unit_keys"].  A
// higher priority results in the work units being scheduled sooner.
func (jobs *JobServer) PrioritizeWorkUnits(workSpecName string, options map[string]interface{}) (bool, string, error) {
	var (
		err      error
		query    coordinate.WorkUnitQuery
		workSpec coordinate.WorkSpec
	)
	pwuOptions := PrioritizeWorkUnitsOptions{
		Priority:   math.NaN(),
		Adjustment: math.NaN(),
	}
	workSpec, err = jobs.Namespace.WorkSpec(workSpecName)
	if err == nil {
		err = decode(&pwuOptions, options)
	}
	if err == nil && pwuOptions.WorkUnitKeys == nil {
		return false, "missing work_unit_keys", err
	}
	if err == nil {
		query.Names = pwuOptions.WorkUnitKeys
		if !math.IsNaN(pwuOptions.Priority) {
			err = workSpec.SetWorkUnitPriorities(query, pwuOptions.Priority)
		} else if !math.IsNaN(pwuOptions.Adjustment) {
			err = workSpec.AdjustWorkUnitPriorities(query, pwuOptions.Adjustment)
		}
	}
	return err == nil, "", err
}
開發者ID:diffeo,項目名稱:go-coordinate,代碼行數:30,代碼來源:units.go

示例13: updateWeights

func (t *GoTracker) updateWeights(vertex int) {
	if t.board[vertex] != EMPTY {
		for i := 0; i < 4; i++ {
			adj := t.adj[vertex][i]
			if adj != -1 && t.board[adj] == EMPTY {
				t.updateWeights(adj)
			}
		}
	} else {
		black_weight := t.weights.Get(BLACK, vertex)
		if black_weight != 0 {
			weight := t.get_weight(BLACK, vertex)
			if math.IsNaN(weight) {
				black_weight = 0
			} else if black_weight+weight > 0 {
				black_weight += weight
			}
		}
		t.weights.Set(BLACK, vertex, black_weight)
		white_weight := t.weights.Get(WHITE, vertex)
		if white_weight != 0 {
			weight := t.get_weight(WHITE, vertex)
			if math.IsNaN(weight) {
				white_weight = 0
			} else if white_weight+weight > 0 {
				white_weight += weight
			}
		}
		t.weights.Set(WHITE, vertex, white_weight)
	}
}
開發者ID:etherealmachine,項目名稱:hivemind,代碼行數:31,代碼來源:gotracker.go

示例14: parseAverages

// parseAverages takes a slice of averages and returns a string representation for flot to graph
func parseAverages(averages []*models.Average, useBtcField bool) string {
	var format string
	if useBtcField {
		format = "[%g, %.8f]"
	} else {
		format = "[%g, %.2f]"
	}

	parsed := ""
	for i, average := range averages {
		if math.IsNaN(average.Cryptsy.Usd) || math.IsNaN(average.Cryptsy.Btc) {
			continue
		}

		timeIndex := float64(average.TimeBlock.Unix()) * 1000.0
		var value float64
		if useBtcField {
			value = average.Cryptsy.Btc
		} else {
			value = average.Cryptsy.Usd
		}

		parsed += fmt.Sprintf(format, timeIndex, value)

		if i < len(averages)-1 {
			parsed += ","
		}
	}

	return parsed
}
開發者ID:robmerrell,項目名稱:btbboard,代碼行數:32,代碼來源:server.go

示例15: funcChanges

// === changes(matrix model.ValMatrix) Vector ===
func funcChanges(ev *evaluator, args Expressions) model.Value {
	in := ev.evalMatrix(args[0])
	out := make(vector, 0, len(in))

	for _, samples := range in {
		changes := 0
		prev := model.SampleValue(samples.Values[0].Value)
		for _, sample := range samples.Values[1:] {
			current := sample.Value
			if current != prev && !(math.IsNaN(float64(current)) && math.IsNaN(float64(prev))) {
				changes++
			}
			prev = current
		}

		rs := &sample{
			Metric:    samples.Metric,
			Value:     model.SampleValue(changes),
			Timestamp: ev.Timestamp,
		}
		rs.Metric.Del(model.MetricNameLabel)
		out = append(out, rs)
	}
	return out
}
開發者ID:PrFalken,項目名稱:prometheus,代碼行數:26,代碼來源:functions.go


注:本文中的math.IsNaN函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。