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


Golang Rat.SetFrac64方法代码示例

本文整理汇总了Golang中math/big.Rat.SetFrac64方法的典型用法代码示例。如果您正苦于以下问题:Golang Rat.SetFrac64方法的具体用法?Golang Rat.SetFrac64怎么用?Golang Rat.SetFrac64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math/big.Rat的用法示例。


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

示例1: PutFrac64

func (me *StatisticalAccumulator) PutFrac64(a, b int64) {

	xx := new(big.Rat)
	xx.SetFrac64(a, b)

	me.PutRat(xx)
}
开发者ID:reiver,项目名称:go-statisticalaccumulator,代码行数:7,代码来源:statisticalaccumulator_put.go

示例2: ParseTimeDuration

// Returns the parsed duration in nanoseconds, support 'u', 's', 'm',
// 'h', 'd', 'W', 'M', and 'Y' suffixes.
func ParseTimeDuration(value string) (int64, error) {
	var constant time.Duration

	prefixSize := 1

	switch value[len(value)-1] {
	case 'u':
		constant = time.Microsecond
	case 's':
		constant = time.Second
	case 'm':
		constant = time.Minute
	case 'h':
		constant = time.Hour
	case 'd':
		constant = 24 * time.Hour
	case 'w', 'W':
		constant = Week
	case 'M':
		constant = Month
	case 'y', 'Y':
		constant = Year
	default:
		prefixSize = 0
	}

	if value[len(value)-2:] == "ms" {
		constant = time.Millisecond
		prefixSize = 2
	}

	t := big.Rat{}
	timeString := value
	if prefixSize > 0 {
		timeString = value[:len(value)-prefixSize]
	}

	_, err := fmt.Sscan(timeString, &t)
	if err != nil {
		return 0, err
	}

	if prefixSize > 0 {
		c := big.Rat{}
		c.SetFrac64(int64(constant), 1)
		t.Mul(&t, &c)
	}

	if t.IsInt() {
		return t.Num().Int64(), nil
	}
	f, _ := t.Float64()
	return int64(f), nil
}
开发者ID:Wikia,项目名称:influxdb,代码行数:56,代码来源:helpers.go

示例3: ParseTimeDuration

// Returns the parsed duration in nanoseconds, support 'u', 's', 'm',
// 'h', 'd' and 'w' suffixes.
func ParseTimeDuration(value string) (int64, error) {
	var constant time.Duration
	hasPrefix := true

	switch value[len(value)-1] {
	case 'u':
		constant = time.Microsecond
	case 's':
		constant = time.Second
	case 'm':
		constant = time.Minute
	case 'h':
		constant = time.Hour
	case 'd':
		constant = 24 * time.Hour
	case 'w':
		constant = 7 * 24 * time.Hour
	case 'y':
		constant = 365 * 24 * time.Hour
	default:
		hasPrefix = false
	}

	t := big.Rat{}
	timeString := value
	if hasPrefix {
		timeString = value[:len(value)-1]
	}

	_, err := fmt.Sscan(timeString, &t)
	if err != nil {
		return 0, err
	}

	if hasPrefix {
		c := big.Rat{}
		c.SetFrac64(int64(constant), 1)
		t.Mul(&t, &c)
	}
	if t.IsInt() {
		return t.Num().Int64(), nil
	}
	f, _ := t.Float64()
	return int64(f), nil
}
开发者ID:9cat,项目名称:influxdb,代码行数:47,代码来源:helpers.go

示例4: main

func main() {
	var recip big.Rat
	max := int64(1 << 19)
	for candidate := int64(2); candidate < max; candidate++ {
		sum := big.NewRat(1, candidate)
		max2 := int64(math.Sqrt(float64(candidate)))
		for factor := int64(2); factor <= max2; factor++ {
			if candidate%factor == 0 {
				sum.Add(sum, recip.SetFrac64(1, factor))
				if f2 := candidate / factor; f2 != factor {
					sum.Add(sum, recip.SetFrac64(1, f2))
				}
			}
		}
		if sum.Denom().Int64() == 1 {
			perfectstring := ""
			if sum.Num().Int64() == 1 {
				perfectstring = "perfect!"
			}
			fmt.Printf("Sum of recipr. factors of %d = %d exactly %s\n",
				candidate, sum.Num().Int64(), perfectstring)
		}
	}
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:24,代码来源:arithmetic-rational.go


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