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


Golang math.Remainder函数代码示例

本文整理汇总了Golang中math.Remainder函数的典型用法代码示例。如果您正苦于以下问题:Golang Remainder函数的具体用法?Golang Remainder怎么用?Golang Remainder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Remainder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: encodeGrid

// encodeGrid encodes a location using the grid refinement method into
// an OLC string.
//
// Appends to the given code byte slice!
//
// The grid refinement method divides the area into a grid of 4x5, and uses a
// single character to refine the area. This allows default accuracy OLC codes
// to be refined with just a single character.
func encodeGrid(code []byte, lat, lng float64, codeLen int) ([]byte, error) {
	latPlaceValue, lngPlaceValue := gridSizeDegrees, gridSizeDegrees
	lat = math.Remainder((lat + latMax), latPlaceValue)
	if lat < 0 {
		lat += latPlaceValue
	}
	lng = math.Remainder((lng + lngMax), lngPlaceValue)
	if lng < 0 {
		lng += lngPlaceValue
	}
	for i := 0; i < codeLen; i++ {
		row := int(math.Floor(lat / (latPlaceValue / gridRows)))
		col := int(math.Floor(lng / (lngPlaceValue / gridCols)))
		pos := row*gridCols + col
		if !(0 <= pos && pos < len(Alphabet)) {
			return nil, fmt.Errorf("pos=%d is out of alphabet", pos)
		}
		code = append(code, Alphabet[pos])
		if i == codeLen-1 {
			break
		}

		latPlaceValue /= gridRows
		lngPlaceValue /= gridCols
		lat -= float64(row) * latPlaceValue
		lng -= float64(col) * lngPlaceValue
	}
	return code, nil
}
开发者ID:mapconcierge,项目名称:open-location-code,代码行数:37,代码来源:encode.go

示例2: encodeGrid

// encodeGrid encodes a location using the grid refinement method into
// an OLC string.
//
// Appends to the given code byte slice!
//
// The grid refinement method divides the area into a grid of 4x5, and uses a
// single character to refine the area. This allows default accuracy OLC codes
// to be refined with just a single character.
func encodeGrid(code []byte, lat, lng float64, codeLen int) []byte {
	latPlaceValue, lngPlaceValue := gridSizeDegrees, gridSizeDegrees
	lat = math.Remainder((lat + latMax), latPlaceValue)
	if lat < 0 {
		lat += latPlaceValue
	}
	lng = math.Remainder((lng + lngMax), lngPlaceValue)
	if lng < 0 {
		lng += lngPlaceValue
	}
	for i := 0; i < codeLen; i++ {
		row := int(math.Floor(lat / (latPlaceValue / gridRows)))
		col := int(math.Floor(lng / (lngPlaceValue / gridCols)))
		pos := row*gridCols + col
		if !(0 <= pos && pos < len(Alphabet)) {
			panic(fmt.Sprintf("encodeGrid loc=(%f,%f) row=%d col=%d latVal=%f lngVal=%f", lat, lng, row, col, latPlaceValue, lngPlaceValue))
		}
		code = append(code, Alphabet[pos])
		if i == codeLen-1 {
			break
		}

		latPlaceValue /= gridRows
		lngPlaceValue /= gridCols
		lat -= float64(row) * latPlaceValue
		lng -= float64(col) * lngPlaceValue
	}
	return code
}
开发者ID:jirisemecky,项目名称:open-location-code,代码行数:37,代码来源:encode.go

示例3: Expanded

// Expanded returns an interval that has been expanded on each side by margin.
// If margin is negative, then the function shrinks the interval on
// each side by margin instead. The resulting interval may be empty or
// full. Any expansion (positive or negative) of a full interval remains
// full, and any expansion of an empty interval remains empty.
func (i Interval) Expanded(margin float64) Interval {
	if margin >= 0 {
		if i.IsEmpty() {
			return i
		}
		// Check whether this interval will be full after expansion, allowing
		// for a 1-bit rounding error when computing each endpoint.
		if i.Length()+2*margin+2*epsilon >= 2*math.Pi {
			return FullInterval()
		}
	} else {
		if i.IsFull() {
			return i
		}
		// Check whether this interval will be empty after expansion, allowing
		// for a 1-bit rounding error when computing each endpoint.
		if i.Length()+2*margin-2*epsilon <= 0 {
			return EmptyInterval()
		}
	}
	result := IntervalFromEndpoints(
		math.Remainder(i.Lo-margin, 2*math.Pi),
		math.Remainder(i.Hi+margin, 2*math.Pi),
	)
	if result.Lo <= -math.Pi {
		result.Lo = math.Pi
	}
	return result
}
开发者ID:jinshuangxian,项目名称:geo,代码行数:34,代码来源:interval.go

示例4: testViewProcedure

func testViewProcedure(t *testing.T, A viewProcedureVector) {
	b := A.ViewProcedure(func(element float64) bool {
		return math.Remainder(element, 2) == 0
	})
	for i := 0; i < b.Size(); i++ {
		el := b.GetQuick(i)
		if math.Remainder(el, 2) != 0 {
			t.Fail()
		}
	}
}
开发者ID:rwl,项目名称:goshawk,代码行数:11,代码来源:vector_view_test.go

示例5: Incr

func (c *Counter) Incr() {
	now := glfw.GetTime()
	if int32(c.Last) != int32(now) {
		c.Total += math.Remainder(now-c.Last, 1)
		c.Count += 1
		avg := c.Total / float64(c.Count)
		c.Avg = float32(avg * 1000)
		c.Total = math.Remainder(now, 1)
		c.Count = 1
	} else {
		c.Total += (now - c.Last)
		c.Count += 1
	}
	c.Last = now
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:15,代码来源:counter.go

示例6: is_even

func is_even(x float64) bool {
	var result bool = false
	if math.Remainder(x, 2) == 0 {
		result = true
	}
	return result
}
开发者ID:cod3ninj4,项目名称:Euler,代码行数:7,代码来源:2.go

示例7: intOp

func intOp(op token.Token, x, y *BasicLit, combine bool) (*BasicLit, error) {
	out := &BasicLit{
		Kind: x.Kind,
	}
	l, err := strconv.Atoi(x.Value)
	if err != nil {
		return out, err
	}
	r, err := strconv.Atoi(y.Value)
	if err != nil {
		return out, err
	}
	var t int
	switch op {
	case token.ADD:
		t = l + r
	case token.SUB:
		t = l - r
	case token.QUO:
		// Sass division can create floats, so much treat
		// ints as floats then test for fitting inside INT
		fl, fr := float64(l), float64(r)
		if math.Remainder(fl, fr) != 0 {
			return floatOp(op, x, y, combine)
		}
		t = l / r
	case token.MUL:
		t = l * r
	default:
		panic("unsupported intOp" + op.String())
	}
	out.Value = strconv.Itoa(t)
	return out, nil
}
开发者ID:wellington,项目名称:sass,代码行数:34,代码来源:calc.go

示例8: div_by_3

func div_by_3(x float64) bool {
	var result bool = false
	if math.Remainder(x, 3) == 0 {
		result = true
	}
	return result
}
开发者ID:cod3ninj4,项目名称:Euler,代码行数:7,代码来源:1.go

示例9: CapBound

// CapBound returns a cap that countains Rect.
func (r Rect) CapBound() Cap {
	// We consider two possible bounding caps, one whose axis passes
	// through the center of the lat-long rectangle and one whose axis
	// is the north or south pole.  We return the smaller of the two caps.

	if r.IsEmpty() {
		return EmptyCap()
	}

	var poleZ, poleAngle float64
	if r.Lat.Hi+r.Lat.Lo < 0 {
		// South pole axis yields smaller cap.
		poleZ = -1
		poleAngle = math.Pi/2 + r.Lat.Hi
	} else {
		poleZ = 1
		poleAngle = math.Pi/2 - r.Lat.Lo
	}
	poleCap := CapFromCenterAngle(PointFromCoords(0, 0, poleZ), s1.Angle(poleAngle)*s1.Radian)

	// For bounding rectangles that span 180 degrees or less in longitude, the
	// maximum cap size is achieved at one of the rectangle vertices.  For
	// rectangles that are larger than 180 degrees, we punt and always return a
	// bounding cap centered at one of the two poles.
	if math.Remainder(r.Lng.Hi-r.Lng.Lo, 2*math.Pi) >= 0 && r.Lng.Hi-r.Lng.Lo < 2*math.Pi {
		midCap := CapFromPoint(PointFromLatLng(r.Center())).AddPoint(PointFromLatLng(r.Lo())).AddPoint(PointFromLatLng(r.Hi()))
		if midCap.Height() < poleCap.Height() {
			return midCap
		}
	}
	return poleCap
}
开发者ID:chelseawangsf,项目名称:geo,代码行数:33,代码来源:rect.go

示例10: GainBeam

func (rx *PhysReceiver) GainBeam(tx EmitterInt, ch int) float64 {

	if ch > 0 && rx.Orientation[ch] >= 0 {

		p := tx.GetPos().Minus(rx.Pos)
		theta := math.Atan2(p.Y, p.X) * 180 / math.Pi
		if theta < 0 {
			theta += 360
		}
		theta -= rx.Orientation[ch]
		theta = math.Remainder(theta, 360)
		//		t1:=o-theta
		//		t2:=theta-o
		//		if t1>t2 {theta=t1} else {theta=t2}
		if theta > 180 {
			theta += 360
		}

		if theta < -180 || theta > 180 {
			fmt.Println("ThetaError")
		}

		g := 12 * (theta / 65) * (theta / 65)
		if g > 20 {
			g = 20
		}

		g = math.Pow(10, (-g+10)/10)

		return g
	}

	return 1.0

}
开发者ID:mirzathegr8,项目名称:GoSynstation,代码行数:35,代码来源:physReceiver.go

示例11: Andoyer

// Andoyer computes approximate geodesic distance between two
// points p1 and p2 on the spheroid s.
// Computations use Andoyer-Lambert first order (in flattening) approximation.
//
// Reference: P.D. Thomas, Mathematical Models for Navigation Systems, TR-182,
// US Naval Oceanographic Office (1965).
func Andoyer(s *Spheroid, p1, p2 LL) float64 {
	a, f := s.A(), s.F()
	lat1, lon1 := p1.LatLon()
	lat2, lon2 := p2.LatLon()

	F, G := (lat1+lat2)/2.0, (lat1-lat2)/2.0
	L := math.Remainder(lon1-lon2, 360.0) / 2.0
	sinF, cosF := math.Sincos((math.Pi / 180.0) * F)
	sinG, cosG := math.Sincos((math.Pi / 180.0) * G)
	sinL, cosL := math.Sincos((math.Pi / 180.0) * L)

	S2 := sq(sinG*cosL) + sq(cosF*sinL)
	C2 := sq(cosG*cosL) + sq(sinF*sinL)
	S, C := math.Sqrt(S2), math.Sqrt(C2)

	omega := math.Atan2(S, C)
	R := (S * C) / omega
	D := 2.0 * omega * a
	H1 := (3.0*R - 1.0) / (2.0 * C2)
	H2 := (3.0*R + 1.0) / (2.0 * S2)
	dist := D * (1.0 + f*(H1*sq(sinF*cosG)-H2*sq(cosF*sinG)))

	if finite(dist) {
		return dist
	}

	// Antipodal points.
	if finite(R) {
		return 2.0 * s.Quad()
	}

	// Identical points.
	return 0.0
}
开发者ID:reconditematter,项目名称:reconditematter,代码行数:40,代码来源:andoyer.go

示例12: handleCommands

func (c *Camera) handleCommands() {
	Pi2 := math.Pi / 2
	for cmd := range c.cmds {
		switch cmd := cmd.(type) {
		case cameraCommandTurn:
			if cmd.X != 0 {
				c.alpha += cmd.X / (float64(c.screenw) / Pi2)
				c.alpha = math.Remainder(c.alpha, 2*math.Pi)
			}
			if cmd.Y != 0 {
				c.theta -= cmd.Y / (float64(c.screenh) / Pi2)
				c.theta = math.Max(-Pi2, math.Min(Pi2, c.theta))
			}
		case cameraCommandMove:
			if cmd.Y != 0 {
				c.Pos.X += float64(cmd.Y) * math.Cos(c.alpha)
				c.Pos.Y += float64(cmd.Y) * math.Sin(c.alpha)
				c.Pos.Z += float64(cmd.Y) * math.Sin(c.theta)
			}

			if cmd.X != 0 {
				c.Pos.X += float64(cmd.X) * math.Cos(c.alpha+Pi2)
				c.Pos.Y += float64(cmd.X) * math.Sin(c.alpha+Pi2)
			}
		case cameraCommandReset:
			c.Pos = vector.V3{}
			c.alpha = 0
			c.theta = 0
		}
	}
}
开发者ID:farhaven,项目名称:universe,代码行数:31,代码来源:camera.go

示例13: fmtEvents

func fmtEvents(events []loggly.Event) string {
	result := make([]string, 0)
	for _, e := range events {
		var text string
		if v, ok := e.Event["json"]; ok {
			v := v.(map[string]interface{})
			logTime, _ := time.Parse(time.RFC3339Nano, v["time"].(string))
			text = fmt.Sprintf("*%v* %v %v %v u:%v", logTime.Format("01-02 15:04:05.000"), v["method"], v["path"], v["status"], v["user_id"])
		} else {
			text = e.Logmsg
			if strings.Contains(e.Logmsg, "#012") {
				text = loggly.FmtHit(e.Logmsg)
			}
			loc, err := time.LoadLocation("Asia/Shanghai")
			if err != nil {
				loc = time.Local
			}
			t := time.Unix(
				e.Timestamp/1000,
				int64(math.Remainder(float64(e.Timestamp), 1000))*time.Millisecond.Nanoseconds(),
			).In(loc).Format("01-02 15:04:05.000")
			text = fmt.Sprintf("*%v* %s", t, text)
		}
		result = append(result, text)
	}
	return strings.Join(result, "\n")
}
开发者ID:hsluo,项目名称:slack-loggly-alert,代码行数:27,代码来源:appengine.go

示例14: LoadTileSpec

// LoadTileSpec loads a TileSpec from JSON data.
// JSON data should look like:
// {
//    "0": { "Resolution": [3.1, 3.1, 40.0], "TileSize": [512, 512, 40] },
//    "1": { "Resolution": [6.2, 6.2, 40.0], "TileSize": [512, 512, 80] },
//    ...
// }
// Each line is a scale with a n-D resolution/voxel and a n-D tile size in voxels.
func LoadTileSpec(data []byte) (TileSpec, error) {
	var config specJSON
	err := json.Unmarshal(data, &config)
	if err != nil {
		return nil, err
	}

	// Allocate the tile specs
	numLevels := len(config)
	specs := make(TileSpec, numLevels)
	dvid.Infof("Found %d scaling levels for imagetile specification.\n", numLevels)

	// Store resolution and tile sizes per level.
	var hires, lores float64
	for scaleStr, levelSpec := range config {
		fmt.Printf("scale %s, levelSpec %v\n", scaleStr, levelSpec)
		scaleLevel, err := strconv.Atoi(scaleStr)
		if err != nil {
			return nil, fmt.Errorf("Scaling '%s' needs to be a number for the scale level.", scaleStr)
		}
		if scaleLevel >= numLevels {
			return nil, fmt.Errorf("Tile levels must be consecutive integers from [0,Max]: Got scale level %d > # levels (%d)\n",
				scaleLevel, numLevels)
		}
		specs[Scaling(scaleLevel)] = TileScaleSpec{LevelSpec: levelSpec}
	}

	// Compute the magnification between each level.
	for scaling := Scaling(0); scaling < Scaling(numLevels-1); scaling++ {
		levelSpec, found := specs[scaling]
		if !found {
			return nil, fmt.Errorf("Could not find tile spec for level %d", scaling)
		}
		nextSpec, found := specs[scaling+1]
		if !found {
			return nil, fmt.Errorf("Could not find tile spec for level %d", scaling+1)
		}
		var levelMag dvid.Point3d
		for i, curRes := range levelSpec.Resolution {
			hires = float64(curRes)
			lores = float64(nextSpec.Resolution[i])
			rem := math.Remainder(lores, hires)
			if rem > 0.001 {
				return nil, fmt.Errorf("Resolutions between scale %d and %d aren't integral magnifications!",
					scaling, scaling+1)
			}
			mag := lores / hires
			if mag < 0.99 {
				return nil, fmt.Errorf("A resolution between scale %d and %d actually increases!",
					scaling, scaling+1)
			}
			mag += 0.5
			levelMag[i] = int32(mag)
		}
		levelSpec.levelMag = levelMag
		specs[scaling] = levelSpec
	}
	return specs, nil
}
开发者ID:jwohlwend,项目名称:dvid,代码行数:67,代码来源:imagetile.go

示例15: RectBound

// RectBound returns a bounding latitude-longitude rectangle.
// The bounds are not guaranteed to be tight.
func (c Cap) RectBound() Rect {
	if c.IsEmpty() {
		return EmptyRect()
	}

	capAngle := c.Radius().Radians()
	allLongitudes := false
	lat := r1.Interval{
		Lo: latitude(c.center).Radians() - capAngle,
		Hi: latitude(c.center).Radians() + capAngle,
	}
	lng := s1.FullInterval()

	// Check whether cap includes the south pole.
	if lat.Lo <= -math.Pi/2 {
		lat.Lo = -math.Pi / 2
		allLongitudes = true
	}

	// Check whether cap includes the north pole.
	if lat.Hi >= math.Pi/2 {
		lat.Hi = math.Pi / 2
		allLongitudes = true
	}

	if !allLongitudes {
		// Compute the range of longitudes covered by the cap. We use the law
		// of sines for spherical triangles. Consider the triangle ABC where
		// A is the north pole, B is the center of the cap, and C is the point
		// of tangency between the cap boundary and a line of longitude. Then
		// C is a right angle, and letting a,b,c denote the sides opposite A,B,C,
		// we have sin(a)/sin(A) = sin(c)/sin(C), or sin(A) = sin(a)/sin(c).
		// Here "a" is the cap angle, and "c" is the colatitude (90 degrees
		// minus the latitude). This formula also works for negative latitudes.
		//
		// The formula for sin(a) follows from the relationship h = 1 - cos(a).
		sinA := math.Sqrt(c.height * (2 - c.height))
		sinC := math.Cos(latitude(c.center).Radians())
		if sinA <= sinC {
			angleA := math.Asin(sinA / sinC)
			lng.Lo = math.Remainder(longitude(c.center).Radians()-angleA, math.Pi*2)
			lng.Hi = math.Remainder(longitude(c.center).Radians()+angleA, math.Pi*2)
		}
	}
	return Rect{lat, lng}
}
开发者ID:hailocab,项目名称:geo,代码行数:48,代码来源:cap.go


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