本文整理汇总了Golang中code/google/com/p/go/tools/go/exact.Value.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.String方法的具体用法?Golang Value.String怎么用?Golang Value.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/tools/go/exact.Value
的用法示例。
在下文中一共展示了Value.String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: valString
// valString returns the string representation for the value v.
// Setting floatFmt forces an integer value to be formatted in
// normalized floating-point format.
// TODO(gri) Move this code into package exact.
func valString(v exact.Value, floatFmt bool) string {
switch v.Kind() {
case exact.Int:
if floatFmt {
return floatString(v)
}
case exact.Float:
return floatString(v)
case exact.Complex:
re := exact.Real(v)
im := exact.Imag(v)
var s string
if exact.Sign(re) != 0 {
s = floatString(re)
if exact.Sign(im) >= 0 {
s += " + "
} else {
s += " - "
im = exact.UnaryOp(token.SUB, im, 0) // negate im
}
}
// im != 0, otherwise v would be exact.Int or exact.Float
return s + floatString(im) + "i"
}
return v.String()
}
示例2: writeInt
func writeInt(w *bytes.Buffer, ev exact.Value, k types.BasicKind) {
if k == types.Uintptr {
u, _ := exact.Uint64Val(ev)
w.WriteString("0x")
w.WriteString(strconv.FormatUint(u, 16))
return
}
w.WriteString(ev.String())
switch k {
case types.Int32:
w.WriteByte('L')
case types.Uint32:
w.WriteString("UL")
case types.Int64:
w.WriteString("LL")
case types.Uint64:
w.WriteString("ULL")
}
}
示例3: Value
func (cdd *CDD) Value(w *bytes.Buffer, ev exact.Value, t types.Type) {
k := t.Underlying().(*types.Basic).Kind()
// TODO: use t instead ev.Kind() in following switch
switch ev.Kind() {
case exact.Int:
writeInt(w, ev, k)
case exact.Float:
writeFloat(w, ev, k)
case exact.Complex:
switch k {
case types.Complex64:
k = types.Float32
case types.Complex128:
k = types.Float64
default:
k = types.UntypedFloat
}
writeFloat(w, exact.Real(ev), k)
im := exact.Imag(ev)
if exact.Sign(im) != -1 {
w.WriteByte('+')
}
writeFloat(w, im, k)
w.WriteByte('i')
case exact.String:
w.WriteString("EGSTR(")
w.WriteString(ev.String())
w.WriteByte(')')
default:
w.WriteString(ev.String())
}
}