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


Golang math.Floor函数代码示例

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


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

示例1: main

func main() {
	a := make([][]float64, size*size)
	b := make([][]float64, size*size)
	c := make([][]float64, size*size)
	for j := 0; j < size; j++ {
		a[j] = make([]float64, size)
		b[j] = make([]float64, size)
		c[j] = make([]float64, size)
	}

	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			a[i][j] = math.Floor(10 * rand.Float64())
			b[i][j] = math.Floor(10 * rand.Float64())
		}
	}

	print(a)
	fmt.Println(determinant(a))
	fmt.Printf("\n")
	print(b)
	c = addition(a, b)
	print(c)
	c = multiplication(a, b)
	print(c)
	c = transpose(c)
	print(c)
}
开发者ID:ergenekonyigit,项目名称:Numerical-Analysis-Examples,代码行数:28,代码来源:matrixoperations.go

示例2: ComposeEffect

func (effect *FadeEffect) ComposeEffect() chan SimpleColor {
	c := make(chan SimpleColor, 1)

	keepLooping := false
	if effect.Repeat < 0 {
		keepLooping = true
	}

	max := max(effect.Color.R, effect.Color.B, effect.Color.G)
	go func() {
		for {

			if effect.Repeat <= 0 && !keepLooping {
				break
			}

			r := int(math.Floor(float64(effect.Color.R) / float64(max) * 100.0))
			g := int(math.Floor(float64(effect.Color.G) / float64(max) * 100.0))
			b := int(math.Floor(float64(effect.Color.B) / float64(max) * 100.0))

			for i := 0; i < int(max); i += 1 {
				c <- SimpleColor{uint8((i * r) / 100), uint8((i * g) / 100), uint8((i * b) / 100)}
				time.Sleep(effect.Delay)
			}

			for i := int(max - 1); i >= 0; i -= 1 {
				c <- SimpleColor{uint8((i * r) / 100), uint8((i * g) / 100), uint8((i * b) / 100)}
				time.Sleep(effect.Delay)
			}
			effect.Repeat--
		}
		close(c)
	}()
	return c
}
开发者ID:studentkittens,项目名称:catlight,代码行数:35,代码来源:catlightd.go

示例3: Floor

func (v3 *Vector3) Floor() *Vector3 {
	v3.X = math.Floor(v3.X)
	v3.Y = math.Floor(v3.Y)
	v3.Z = math.Floor(v3.Z)

	return v3
}
开发者ID:uzudil,项目名称:three.go,代码行数:7,代码来源:Vector3.go

示例4: Get

// Get finds a value within (quantile - tolerance) * n <= value <= (quantile + tolerance) * n
// or 0 if no values have been observed.
func (est *Estimator) Get(quantile float64) float64 {
	if est.observations == 0 {
		return 0
	}

	est.flush()

	cur := est.head
	if cur == nil {
		return 0
	}

	midrank := math.Floor(quantile * est.observations)
	maxrank := midrank + math.Floor(est.invariant(midrank, est.observations)/2)

	rank := 0.0
	for cur.next != nil {
		rank += cur.rank
		if rank+cur.next.rank+cur.next.delta > maxrank {
			return cur.v
		}
		cur = cur.next
	}
	return cur.v
}
开发者ID:tsenart,项目名称:quantile,代码行数:27,代码来源:quantile.go

示例5: Encode

// Encode converts the path to a string using the Google Maps Polyline Encoding method.
// Factor defaults to 1.0e5, the same used by Google for polyline encoding.
func (p *Path) Encode(factor ...int) string {
	f := 1.0e5
	if len(factor) != 0 {
		f = float64(factor[0])
	}

	var pLat int
	var pLng int

	var result bytes.Buffer
	scratch1 := make([]byte, 0, 50)
	scratch2 := make([]byte, 0, 50)

	for _, p := range p.PointSet {
		lat5 := int(math.Floor(p.Lat()*f + 0.5))
		lng5 := int(math.Floor(p.Lng()*f + 0.5))

		deltaLat := lat5 - pLat
		deltaLng := lng5 - pLng

		pLat = lat5
		pLng = lng5

		result.Write(append(encodeSignedNumber(deltaLat, scratch1), encodeSignedNumber(deltaLng, scratch2)...))

		scratch1 = scratch1[:0]
		scratch2 = scratch2[:0]
	}

	return result.String()
}
开发者ID:thomaspeugeot,项目名称:go.geo,代码行数:33,代码来源:path.go

示例6: Render

func (p *GesturePane) Render() (*image.RGBA, error) {
	img := image.NewRGBA(image.Rect(0, 0, 16, 16))

	if p.last != nil {

		x := math.Floor(float64(p.last.Position.X)/float64(0xffff)*float64(16)) + 0.5
		y := math.Floor(float64(p.last.Position.Y)/float64(0xffff)*float64(16)) + 0.5
		z := math.Floor(float64(p.last.Position.Z)/float64(0xffff)*float64(16)) + 0.5

		r, _ := colorful.Hex("#FF000")
		g, _ := colorful.Hex("#00FF00")
		b, _ := colorful.Hex("#0000FF")

		gc := draw2d.NewGraphicContext(img)

		gc.SetStrokeColor(r)
		gc.MoveTo(0, x)
		gc.LineTo(16, x)
		gc.Stroke()

		gc.SetStrokeColor(g)
		gc.MoveTo(y, 0)
		gc.LineTo(y, 16)
		gc.Stroke()

		gc.SetStrokeColor(b)
		gc.MoveTo(16-z, 0)
		gc.LineTo(16-z, 16)
		gc.Stroke()
	}

	return img, nil
}
开发者ID:ninjasphere,项目名称:sphere-go-led-controller,代码行数:33,代码来源:GesturePane.go

示例7: RGBColorDivNumber

func RGBColorDivNumber(c *ast.RGBColor, n *ast.Number) *ast.RGBColor {
	var val = n.Value
	var r = math.Floor(float64(c.R) / val)
	var g = math.Floor(float64(c.G) / val)
	var b = math.Floor(float64(c.B) / val)
	return ast.NewRGBColor(uint32(r), uint32(g), uint32(b), nil)
}
开发者ID:se77en,项目名称:c6,代码行数:7,代码来源:color.go

示例8: main

func main() {
	bi := bufio.NewReader(os.Stdin)
	bo := bufio.NewWriter(os.Stdout)
	defer bo.Flush()

	var p_fl, q_fl float64
	fmt.Fscan(bi, &p_fl, &q_fl)

	p := int64(math.Floor(p_fl*100.0 + .5))
	q := int64(math.Floor(q_fl*100.0 + .5))

	var k int64
	for k = 1; true; k++ {
		kk := 10000 * k
		pp := kk / p
		qq := kk / q
		if qq < pp {
			if kk%p == 0 && pp-qq == 1 {
				// special case: 10000 * k ~ p
			} else {
				break
			}
		}
	}

	fmt.Fprintln(bo, 10000*k/q+1)
}
开发者ID:esix,项目名称:competitive-programming,代码行数:27,代码来源:solution.go

示例9: CheckCollision

func CheckCollision(pb *box, dx, dy float64) (col bool, nx, ny float64) {
	for x := int(math.Floor(pb.x/tileSize) - 1); x <= int(math.Ceil((pb.x+pb.w)/tileSize)+1); x++ {
		for y := int(math.Floor(pb.y/tileSize) - 1); y <= int(math.Ceil((pb.y+pb.h)/tileSize)+1); y++ {
			t := GetTile(x, y)
			if t.IsSolid() {
				b := &box{
					x: float64(x) * tileSize,
					y: float64(y) * tileSize,
					w: tileSize, h: tileSize,
				}
				if b.collides(pb) {
					col = true
					if dx < 0 {
						nx = b.x + b.w + 0.001
					} else if dx > 0 {
						nx = b.x - pb.w - 0.001
					}
					if dy < 0 {
						ny = b.y + b.h + 0.001
					} else if dy > 0 {
						ny = b.y - pb.h - 0.001
					}
					nx /= tileSize
					ny /= tileSize
					return
				}
			}
		}
	}
	return
}
开发者ID:Thinkofname,项目名称:monstergame,代码行数:31,代码来源:entity.go

示例10: TrimMean

// TrimMean returns the mean of the interior of a supplied set of values
// Array  -	An array of numeric values, for which you want to calculate the trimmed mean
// Percent	-	The percentage of values that you want to be discarded from the supplied array
func TrimMean(percent float64, arrays ...float64) (float64, error) {

	// First find n = number of observations
	n := float64(len(arrays))

	// Reorder them as "order statistics" Xi from the smallest to the largest
	sort.Sort(SmallNums(arrays))

	if math.IsNaN(percent) {
		return 0.0, errors.New("#VALUE!	-	Occurred because the percent argument cannot be interpreted as a Numeric value")
	}

	// Find lower case p=P/100 = proportion trimmed
	p := percent / 100.00

	if p < 0 || p > 1 {
		return 0.0, errors.New("#NUM!, Occurred the supplied percent argument is < 0 or > 1")
	}

	// If np is an integer use k=np and trim k observations at both ends.
	k := math.Floor((n * p) / 2)

	//r = remaining observations = n−2k
	r := n - (2 * k)

	k = math.Floor(k)

	// Trimmed mean = (1/R)(Xk+1+Xk+2+…+Xn−k)
	sum := 0.0
	for i := int(k); i <= int(n-k-1); i++ {
		sum += arrays[i]
	}
	return (1 / r) * sum, nil
}
开发者ID:muyiwaolurin,项目名称:spreadsheet-functions,代码行数:37,代码来源:trimmean.go

示例11: Accept

func (g Raster) Accept(visitor Visitor) {
	c := new(Composite)
	hc := math.Floor(g.Width / g.Dx / 2)
	vc := math.Floor(g.Height / g.Dy / 2)
	hw := g.Width / 2
	hh := g.Height / 2
	if g.Dx != 0 {
		for i := -hc; i <= hc; i++ {
			x := i*g.Dx + g.Center.X
			segment := LineSegment{P(x, g.Center.Y-hh), P(x, g.Center.Y+hh)}
			c.Add(segment)
		}
	} else {
		segment := LineSegment{P(g.Center.X, g.Center.Y-hh), P(g.Center.X, g.Center.Y+hh)}
		c.Add(segment)
	}
	if g.Dy != 0 {
		for i := -vc; i <= vc; i++ {
			y := i*g.Dy + g.Center.Y
			segment := LineSegment{P(g.Center.X-hw, y), P(g.Center.X+hw, y)}
			c.Add(segment)
		}
	} else {
		segment := LineSegment{P(g.Center.X-hw, g.Center.Y), P(g.Center.X+hw, g.Center.Y)}
		c.Add(segment)
	}
	c.Accept(visitor)
}
开发者ID:emicklei,项目名称:zenna,代码行数:28,代码来源:raster.go

示例12: Colliding

func (e *Entity) Colliding() bool {
	playerSize := .5
	sx := int(math.Floor(e.x - playerSize/2))
	sy := int(math.Floor(e.y - playerSize/2))
	sz := int(math.Floor(e.z - playerSize/2))
	lx := int(math.Ceil(e.x + playerSize/2))
	ly := int(math.Ceil(e.y + playerSize/2))
	lz := int(math.Ceil(e.z + playerSize/2))
	if sx < 0 || lx >= worldW || sz < 0 || lz >= worldD {
		return true
	}
	if sy < 0 || ly >= worldH {
		return false
	}
	for ix := sx; ix < lx; ix += 1 {
		for iy := sy; iy < ly; iy += 1 {
			for iz := sz; iz < lz; iz += 1 {
				blockType := level[ix][iy][iz]
				if blockType > 0 {
					return true
				}
			}
		}
	}
	return false
}
开发者ID:dantoye,项目名称:bots,代码行数:26,代码来源:clients.go

示例13: square

func square(im *webimg.Image, size int) error {
	im_cols, _ := webimg.Wi_get_cols(im)
	im_rows, _ := webimg.Wi_get_rows(im)

	var x, y, cols int

	if im_cols > im_rows {
		cols = im_rows
		y = 0
		x = int(math.Floor(float64(im_cols-im_rows) / 2.0))
	} else {
		cols = im_cols
		x = 0
		y = int(math.Floor(float64(im_rows-im_cols) / 2.0))
	}

	_, err := webimg.Wi_crop(im, x, y, cols, cols)
	if err != nil {
		return err
	}

	_, err = webimg.Wi_scale(im, size, 0)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:shitfSign,项目名称:gowebimg,代码行数:27,代码来源:square.go

示例14: mouseButtonCallback

func mouseButtonCallback(button, state int) {
	if currExX != -1 || currExY != -1 || mouseLock || len(selectedHex) < 3 {
		return
	}
	x, y := glfw.MousePos()

	if state == glfw.KeyPress {
		switch button {
		case glfw.MouseLeft:
			// fmt.Println(x, y)
			currExX = int(math.Floor((float64(x) - 80) / 33))
			currExY = int(math.Floor((float64(y) - 80 - 19) / 38))
			if currExX%2 == 1 {
				currExY = (y - 80) / 36
			}
			if currExX > 9 || currExY > 8 || currExX < 0 || currExY < 0 {
				currExX = -1
				currExY = -1
				return
			}
			if hexMap[currExX][currExY] == 6 && currExX > 0 && currExX < 9 && currExY > 0 && (currExX%2 == 0 && currExY < 7 || currExX%2 == 1 && currExY < 8) {
				starRotate = true
			}
			timesToRotate = 2
			mouseLock = true
			fmt.Println("Mouse locked")
			// fmt.Println(currExX, currExY)
			// renderHexMap(currExX, currExY)
		}
	}
}
开发者ID:TheOnly92,项目名称:gexic,代码行数:31,代码来源:main.go

示例15: AsInt

// AsInt accepts an int or float64 value and converts it to an int value.
func AsInt(v interface{}) int {
	switch t := v.(type) {
	case int:
		return t
	case float64:
		if math.Floor(t) == t {
			return int(t)
		}
		panic("precision")
	case complex128:
		if imag(t) != 0 {
			panic("imaginary integers")
		}
		f := real(t)
		if math.Floor(f) == f {
			return int(f)
		}
		panic("real precision")
	case string:
		i, err := strconv.Atoi(t)
		if err != nil {
			panic("illegible integer")
		}
		return i
	}
	panic(4)
}
开发者ID:mrG7,项目名称:escher,代码行数:28,代码来源:plumb.go


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