當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Float.Text方法代碼示例

本文整理匯總了Golang中math/big.Float.Text方法的典型用法代碼示例。如果您正苦於以下問題:Golang Float.Text方法的具體用法?Golang Float.Text怎麽用?Golang Float.Text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在math/big.Float的用法示例。


在下文中一共展示了Float.Text方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Encode

func (sed StringEncoderDecoder) Encode(w io.Writer, n *big.Float) error {
	// TODO - big.Float.MarshalText?
	// TODO - big.Float.Append
	str := []byte(n.Text('g', -1))
	_, err := w.Write(str)
	return err
}
開發者ID:Richardphp,項目名稱:noms,代碼行數:7,代碼來源:string-encoder.go

示例2: String

func (m *meanagg) String() string {
	if m.d == 0 {
		return "NaN"
	}
	v := new(big.Float).Quo(m.v, big.NewFloat(m.d))
	return v.Text('f', -1)
}
開發者ID:robinjha,項目名稱:clair,代碼行數:7,代碼來源:num.go

示例3: BigCommaf

// BigCommaf produces a string form of the given big.Float in base 10
// with commas after every three orders of magnitude.
func BigCommaf(v *big.Float) string {
	buf := &bytes.Buffer{}
	if v.Sign() < 0 {
		buf.Write([]byte{'-'})
		v.Abs(v)
	}

	comma := []byte{','}

	parts := strings.Split(v.Text('f', -1), ".")
	pos := 0
	if len(parts[0])%3 != 0 {
		pos += len(parts[0]) % 3
		buf.WriteString(parts[0][:pos])
		buf.Write(comma)
	}
	for ; pos < len(parts[0]); pos += 3 {
		buf.WriteString(parts[0][pos : pos+3])
		buf.Write(comma)
	}
	buf.Truncate(buf.Len() - 1)

	if len(parts) > 1 {
		buf.Write([]byte{'.'})
		buf.WriteString(parts[1])
	}
	return buf.String()
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:30,代碼來源:commaf.go

示例4: ExampleFloat_Add

func ExampleFloat_Add() {
	// Operate on numbers of different precision.
	var x, y, z big.Float
	x.SetInt64(1000)          // x is automatically set to 64bit precision
	y.SetFloat64(2.718281828) // y is automatically set to 53bit precision
	z.SetPrec(32)
	z.Add(&x, &y)
	fmt.Printf("x = %.10g (%s, prec = %d, acc = %s)\n", &x, x.Text('p', 0), x.Prec(), x.Acc())
	fmt.Printf("y = %.10g (%s, prec = %d, acc = %s)\n", &y, y.Text('p', 0), y.Prec(), y.Acc())
	fmt.Printf("z = %.10g (%s, prec = %d, acc = %s)\n", &z, z.Text('p', 0), z.Prec(), z.Acc())
	// Output:
	// x = 1000 (0x.fap+10, prec = 64, acc = Exact)
	// y = 2.718281828 (0x.adf85458248cd8p+2, prec = 53, acc = Exact)
	// z = 1002.718282 (0x.faadf854p+10, prec = 32, acc = Below)
}
開發者ID:achanda,項目名稱:go,代碼行數:15,代碼來源:floatexample_test.go

示例5: String

func (f BigFloat) String() string {
	var mant big.Float
	exp := f.Float.MantExp(&mant)
	positive := 1
	if exp < 0 {
		positive = 0
		exp = -exp
	}
	verb, prec := byte('g'), 12
	format := conf.Format()
	if format != "" {
		v, p, ok := conf.FloatFormat()
		if ok {
			verb, prec = v, p
		}
	}
	// Printing huge floats can be very slow using
	// big.Float's native methods; see issue #11068.
	// For example 1e5000000 takes a minute of CPU time just
	// to print. The code below is instantaneous, by rescaling
	// first. It is however less feature-complete.
	// (Big ints are problematic too, but if you print 1e50000000
	// as an integer you probably won't be surprised it's slow.)

	if fastFloatPrint && exp > 10000 {
		// We always use %g to print the fraction, and it will
		// never have an exponent, but if the format is %E we
		// need to use a capital E.
		eChar := 'e'
		if verb == 'E' || verb == 'G' {
			eChar = 'E'
		}
		fexp := newF().SetInt64(int64(exp))
		fexp.Mul(fexp, floatLog2)
		fexp.Quo(fexp, floatLog10)
		// We now have a floating-point base 10 exponent.
		// Break into the integer part and the fractional part.
		// The integer part is what we will show.
		// The 10**(fractional part) will be multiplied back in.
		iexp, _ := fexp.Int(nil)
		fraction := fexp.Sub(fexp, newF().SetInt(iexp))
		// Now compute 10**(fractional part).
		// Fraction is in base 10. Move it to base e.
		fraction.Mul(fraction, floatLog10)
		scale := exponential(fraction)
		if positive > 0 {
			mant.Mul(&mant, scale)
		} else {
			mant.Quo(&mant, scale)
		}
		ten := newF().SetInt64(10)
		i64exp := iexp.Int64()
		// For numbers not too far from one, print without the E notation.
		// Shouldn't happen (exp must be large to get here) but just
		// in case, we keep this around.
		if -4 <= i64exp && i64exp <= 11 {
			if i64exp > 0 {
				for i := 0; i < int(i64exp); i++ {
					mant.Mul(&mant, ten)
				}
			} else {
				for i := 0; i < int(-i64exp); i++ {
					mant.Quo(&mant, ten)
				}
			}
			return fmt.Sprintf("%g\n", &mant)
		} else {
			sign := ""
			if mant.Sign() < 0 {
				sign = "-"
				mant.Neg(&mant)
			}
			// If it has a leading zero, rescale.
			digits := mant.Text('g', prec)
			for digits[0] == '0' {
				mant.Mul(&mant, ten)
				if positive > 0 {
					i64exp--
				} else {
					i64exp++
				}
				digits = mant.Text('g', prec)
			}
			return fmt.Sprintf("%s%s%c%c%d", sign, digits, eChar, "-+"[positive], i64exp)
		}
	}
	return f.Float.Text(verb, prec)
}
開發者ID:zzn01,項目名稱:ivy,代碼行數:88,代碼來源:bigfloat.go

示例6: stringOfBigFloat

// helpful in debugging output
func stringOfBigFloat(n *big.Float) string {
	return n.Text('g', -1)
}
開發者ID:Richardphp,項目名稱:noms,代碼行數:4,代碼來源:main.go

示例7: FormatNumberBigFloat

// FormatNumberBigFloat only supports *big.Float value.
// It is faster than FormatNumber, because it does not do any runtime type evaluation.
func FormatNumberBigFloat(x *big.Float, precision int, thousand string, decimal string) string {
	return formatNumberString(x.Text('f', precision), precision, thousand, decimal)
}
開發者ID:sivagollapalli,項目名稱:accounting,代碼行數:5,代碼來源:formatnumber15.go

示例8: emitBig

func emitBig(b *big.Float) string {
	digits := bits2digits(b.MinPrec())
	return b.Text('e', int(digits))
}
開發者ID:johnny-morrice,項目名稱:godelbrot,代碼行數:4,代碼來源:util.go


注:本文中的math/big.Float.Text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。