本文整理汇总了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())
}
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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++
}
}
示例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
}
}
示例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))
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}