當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。