本文整理汇总了Golang中math.Pow10函数的典型用法代码示例。如果您正苦于以下问题:Golang Pow10函数的具体用法?Golang Pow10怎么用?Golang Pow10使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pow10函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: adjustFracToPrec
// adjustFracToPrec adapts the fractal value of a float64 number to the format
// precision. Rounds the value.
func (f *format) adjustFracToPrec(frac int64, prec int) int64 {
if f.precision > prec {
// Moving frac values to the correct precision.
// Edge case when format has a higher precision than prec.
// E.G.: Format is #,##0.000 and prec=2 and frac=8 (1234.08)
// the re-calculated frac is then 8*(10^2) = 80 to move
// 8 to the second place. The new number would be then 1234.080 because
// the format requires to have 3 fractal digits
frac *= int64(math.Pow10(f.precision - prec))
}
// if the prec is higher than the formatted precision then we have to round
// the frac value to fit into the precision of the format.
if prec > 0 && prec > f.precision {
il10 := math.Pow10(prec)
ilf := float64(frac) / il10
prec10 := math.Pow10(f.precision)
fracf := float64((ilf*prec10)+0.55) / prec10 // hmmm that .55 needs to be monitored. everywhere else we have just .5
fracf *= prec10
fracf += floatRoundingCorrection // I'm lovin it 8-)
return int64(fracf)
}
return frac
}
示例2: MakePrefices
// make the prefix structure
func MakePrefices() map[string]SIPrefix {
pref_map := make(map[string]SIPrefix, 20)
exponent := -24
pfcs := "yzafpnum"
for _, rune := range pfcs {
prefix := SIPrefix{string(rune), math.Pow10(exponent)}
// fmt.Println(prefix)
pref_map[string(rune)] = prefix
exponent += 3
}
pfcs = "cd h"
exponent = -2
for _, rune := range pfcs {
prefix := SIPrefix{string(rune), math.Pow10(exponent)}
pref_map[string(rune)] = prefix
exponent += 1
}
exponent = 3
pfcs = "kMGTPEZY"
for _, rune := range pfcs {
prefix := SIPrefix{string(rune), math.Pow10(exponent)}
// fmt.Println(prefix)
pref_map[string(rune)] = prefix
exponent += 3
}
return pref_map
}
示例3: maxPalindrome3
func maxPalindrome3(digits int) long {
top := long(math.Pow10(digits) - 1)
min := long(math.Pow10(digits - 1))
largestPalindrome := long(0)
pow11 := top - top%11 //The largest number less than or equal top and divisible by 11
//n := 0
for a := top; a >= min; a-- {
//n++
b := pow11
db := long(11)
if a%11 == 0 {
b = top
db = 1
}
for ; b >= min; b -= db {
//n++
c := a * b
if c < largestPalindrome {
break
}
if isPalindrome(c) {
largestPalindrome = c
}
}
}
//fmt.Println("n", n)
return largestPalindrome
}
示例4: NiceNum
// NiceNum finds a "nice" number approximately equal to x. Round the number if round is true, otherwise take the
// ceiling. Described on Graphics Gems pg. 63
func NiceNum(x float64, round bool) float64 {
exp := int(math.Floor(math.Log10(x)))
f := x / math.Pow10(exp)
var nf int
if round {
if f < 1.5 {
nf = 1
} else if f < 3 {
nf = 2
} else if f < 7 {
nf = 5
} else {
nf = 10
}
} else {
if f <= 1 {
nf = 1
} else if f <= 2 {
nf = 2
} else if f <= 5 {
nf = 5
} else {
nf = 10
}
}
return float64(nf) * math.Pow10(exp)
}
示例5: NewData
func NewData(digit, substart, sublen uint) *Data {
maxL := int(sublen)
maxNum := int(math.Pow10(maxL)) - 1
maxDiv := int(math.Sqrt(float64(maxNum)))
pb := make([]bool, maxDiv+1)
for i, _ := range pb {
pb[i] = false
}
pb[0] = true
pb[1] = true
maxPb := int(math.Sqrt(float64(maxDiv + 1)))
for i := 2; i <= maxPb; i++ {
if pb[i] {
continue
}
for j := i * i; j < maxDiv+1; j += i {
pb[j] = true
}
}
fmt.Println("prime buffer")
for _, j := range pb {
fmt.Print(" ", j)
}
fmt.Println()
b := make([]int, digit)
for i, _ := range b {
b[i] = i
}
base := int(math.Pow10(int(sublen) - 1))
return &Data{pb, b, int(digit), int(substart), int(sublen), base}
}
示例6: Round
func Round(input float64, decimals int) float64 {
input = input * math.Pow10(decimals)
if input < 0 {
return math.Ceil(input-0.5) / math.Pow10(decimals)
}
return math.Floor(input+0.5) / math.Pow10(decimals)
}
示例7: extractDigit
func extractDigit(number int, digit int) int {
x := number
//cut off via modula
x = x % int(math.Pow10(1+digit))
//cut off the remainder
x = x / int(math.Pow10(digit))
return x
}
示例8: over
func over(n, k, d int) int {
x := k * int(math.Pow10(d))
y := n % int(math.Pow10(d+1))
y /= int(math.Pow10(d))
y *= int(math.Pow10(d))
if x > y {
return 1
} else if x < y {
return -1
}
return 0
}
示例9: scaledValue
// scaledValue scales given unscaled value from scale to new Scale and returns
// an int64. It ALWAYS rounds up the result when scale down. The final result might
// overflow.
//
// scale, newScale represents the scale of the unscaled decimal.
// The mathematical value of the decimal is unscaled * 10**(-scale).
func scaledValue(unscaled *big.Int, scale, newScale int) int64 {
dif := scale - newScale
if dif == 0 {
return unscaled.Int64()
}
// Handle scale up
// This is an easy case, we do not need to care about rounding and overflow.
// If any intermediate operation causes overflow, the result will overflow.
if dif < 0 {
return unscaled.Int64() * int64(math.Pow10(-dif))
}
// Handle scale down
// We have to be careful about the intermediate operations.
// fast path when unscaled < max.Int64 and exp(10,dif) < max.Int64
const log10MaxInt64 = 19
if unscaled.Cmp(maxInt64) < 0 && dif < log10MaxInt64 {
divide := int64(math.Pow10(dif))
result := unscaled.Int64() / divide
mod := unscaled.Int64() % divide
if mod != 0 {
return result + 1
}
return result
}
// We should only convert back to int64 when getting the result.
divisor := intPool.Get().(*big.Int)
exp := intPool.Get().(*big.Int)
result := intPool.Get().(*big.Int)
defer func() {
intPool.Put(divisor)
intPool.Put(exp)
intPool.Put(result)
}()
// divisor = 10^(dif)
// TODO: create loop up table if exp costs too much.
divisor.Exp(bigTen, exp.SetInt64(int64(dif)), nil)
// reuse exp
remainder := exp
// result = unscaled / divisor
// remainder = unscaled % divisor
result.DivMod(unscaled, divisor, remainder)
if remainder.Sign() != 0 {
return result.Int64() + 1
}
return result.Int64()
}
示例10: generateTemplate
func (cons *Profiler) generateTemplate() []byte {
var dummyValues []interface{}
messageLen := len(cons.message)
for idx, char := range cons.message {
if char == '%' {
// Get the required length
size := 0
searchIdx := idx + 1
// Get format size
for searchIdx < messageLen && cons.message[searchIdx] >= '0' && cons.message[searchIdx] <= '9' {
size = size*10 + int(cons.message[searchIdx]-'0')
searchIdx++
}
// Skip decimal places
if cons.message[searchIdx] == '.' {
searchIdx++
for searchIdx < messageLen && cons.message[searchIdx] >= '0' && cons.message[searchIdx] <= '9' {
searchIdx++
}
}
// Make sure there is at least 1 number / character
if size == 0 {
size = 1
}
// Generate values
switch cons.message[searchIdx] {
case '%':
// ignore
case 'e', 'E', 'f', 'F', 'g', 'G':
dummyValues = append(dummyValues, rand.Float64()*math.Pow10(size))
case 'U', 'c':
dummyValues = append(dummyValues, rune(rand.Intn(1<<16)+32))
case 'd', 'b', 'o', 'x', 'X':
dummyValues = append(dummyValues, rand.Intn(int(math.Pow10(size))))
case 's', 'q', 'v', 'T':
fallthrough
default:
dummyValues = append(dummyValues, cons.generateString(size))
}
}
}
return []byte(fmt.Sprintf(cons.message, dummyValues...))
}
示例11: adjustValue
// ADC Correction
func adjustValue(v float64, adj AdjustmentTable) float64 {
if adj.Orders == 4 {
return adj.Order[0] + adj.Order[1]*v + adj.Order[2]*math.Pow10(-9)*math.Pow(v, 2) + adj.Order[3]*math.Pow10(-13)*math.Pow(v, 3)
} else if adj.Orders == 3 {
return adj.Order[0] + adj.Order[1]*v + adj.Order[2]*math.Pow10(-9)*math.Pow(v, 2)
} else if adj.Orders == 2 {
return adj.Order[0] + adj.Order[1]*v
} else if adj.Orders == 1 {
return adj.Order[0] + v
}
return v
}
示例12: abc
func abc() {
type T struct {
a int
b int
c float64
}
type SliceHeader struct {
addr uintptr
len int
cap int
}
t := &T{a: 1, b: 2, c: 3.2}
p := unsafe.Sizeof(*t)
println("t size:", int(p))
fmt.Println("t value:", t)
sl := &SliceHeader{
addr: uintptr(unsafe.Pointer(t)),
len: int(p),
cap: int(p),
}
b := *(*[]byte)(unsafe.Pointer(sl))
println("byte size: ", len(b))
fmt.Println("byte content: ", b)
b[0] = 12
b[7] = 0
b[8] = 24
fmt.Println("last t value: ", t)
fmt.Println("last byte content: ", b)
ft := 10.1234567
ftval := 0.0
lastVal := math.Pow10(-4)
addVal := math.Pow10(-5)
fmt.Printf("add val: %f\n", addVal)
tmp := math.Mod(math.Trunc(ft/addVal), 10)
fmt.Printf("tmp val: %f\n", tmp)
if tmp >= 5 {
ftval = ft + lastVal
} else {
ftval = ft
}
fmt.Println(math.Trunc(ftval/lastVal) / math.Pow10(4))
}
示例13: RoundDec64
// RoundDec64 round to prec precision.
func RoundDec64(x float64, prec int) float64 {
if prec < 1 {
return x
}
dec1 := math.Pow10(prec)
dec2 := math.Pow10(prec + 1)
tmp := int(x * dec1)
last := int(x*dec2) - tmp*10
if norm(last) >= 5 && last >= 0 {
tmp += 1
} else if norm(last) >= 5 && last < 0 {
tmp -= 1
}
return float64(tmp) / dec1
}
示例14: getDigit
func getDigit(h int64, r int) int {
max := MaxZoom(h)
p1 := int64(math.Pow10(max - r))
p2 := int64(math.Pow10(max - r + 1))
r1 := int(h / p1)
r2 := int(h/p2) * 10
if r2 == 0 {
return r1
}
return r1 - r2
}
示例15: IntToDig
/* Gets digits of an integer */
func IntToDig(n int64) []int64 {
var (
f []int64
t int64
exp int64
last int
search_digit bool
)
search_digit = false
for e := 19; e >= 0; e-- {
exp = int64(math.Pow10(e))
t = n / exp
if search_digit {
f[last-e] = t
n = n % exp
} else if t != 0 {
f = make([]int64, e+1)
last = e
f[0] = t
n = n % exp
search_digit = true
}
}
return f
}