f := newMpflt()
f.Set(&u.Real)
if u.Imag.CmpFloat64(0) != 0 {
- yyerror("constant %v truncated to real", cconv(u))
+ yyerror("constant %v truncated to real", u.GoString())
}
v.U = f
}
// value from the error message.
// (See issue #11371).
var t big.Float
- t.Parse(fconv(u), 10)
+ t.Parse(u.GoString(), 10)
if t.IsInt() {
yyerror("constant truncated to integer")
} else {
- yyerror("constant %v truncated to integer", fconv(u))
+ yyerror("constant %v truncated to integer", u.GoString())
}
}
}
case *Mpcplx:
i := new(Mpint)
if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 {
- yyerror("constant %v truncated to integer", cconv(u))
+ yyerror("constant %v truncated to integer", u.GoString())
}
v.U = i
// *types.Type:
// %#v Go format
// %#L type definition instead of name
-// %#S omit"func" and receiver in function signature
+// %#S omit "func" and receiver in function signature
//
// %-v type identifiers
// %-S type identifiers without "func" and arg names in type signatures (methodsym)
case *Mpint:
if !u.Rune {
if flag&FmtSharp != 0 {
- fmt.Fprint(s, bconv(u))
+ fmt.Fprint(s, u.String())
return
}
- fmt.Fprint(s, u.String())
+ fmt.Fprint(s, u.GoString())
return
}
fmt.Fprint(s, u.String())
return
}
- fmt.Fprint(s, fconv(u))
+ fmt.Fprint(s, u.GoString())
return
case *Mpcplx:
- switch {
- case flag&FmtSharp != 0:
- fmt.Fprintf(s, "(%v+%vi)", &u.Real, &u.Imag)
-
- case v.U.(*Mpcplx).Real.CmpFloat64(0) == 0:
- fmt.Fprintf(s, "%vi", fconv(&u.Imag))
-
- case v.U.(*Mpcplx).Imag.CmpFloat64(0) == 0:
- fmt.Fprint(s, fconv(&u.Real))
-
- default:
- fmt.Fprintf(s, "(%v)", cconv(u))
+ if flag&FmtSharp != 0 {
+ fmt.Fprint(s, u.String())
+ return
}
+ fmt.Fprint(s, u.GoString())
+ return
case string:
fmt.Fprint(s, strconv.Quote(u))
return "error"
}
- // Unless the 'l' flag was specified, if the type has a name, just print that name.
+ // Unless the 'L' flag was specified, if the type has a name, just print that name.
if flag&FmtLong == 0 && t.Sym != nil && t != types.Types[t.Etype] {
switch mode {
case FTypeId, FTypeIdName:
func (n *Node) nodefmt(s fmt.State, flag FmtFlag, mode fmtMode) {
t := n.Type
- // We almost always want the original, except in export mode for literals.
- // This saves the importer some work, and avoids us having to redo some
- // special casing for package unsafe.
+ // We almost always want the original.
+ // TODO(gri) Why the special case for OLITERAL?
if n.Op != OLITERAL && n.Orig != nil {
n = n.Orig
}
return f.Val.Text('b', 0)
}
-func fconv(fvp *Mpflt) string {
+func (fvp *Mpflt) GoString() string {
// determine sign
sign := ""
f := &fvp.Val
return true
}
-func cconv(v *Mpcplx) string {
- re := fconv(&v.Real)
- im := fconv(&v.Imag)
- if im[0] == '-' {
- return re + im + "i"
+func (v *Mpcplx) String() string {
+ return fmt.Sprintf("(%s+%si)", v.Real.String(), v.Imag.String())
+}
+
+func (v *Mpcplx) GoString() string {
+ var re string
+ sre := v.Real.CmpFloat64(0)
+ if sre != 0 {
+ re = v.Real.GoString()
+ }
+
+ var im string
+ sim := v.Imag.CmpFloat64(0)
+ if sim != 0 {
+ im = v.Imag.GoString()
+ }
+
+ switch {
+ case sre == 0 && sim == 0:
+ return "0"
+ case sre == 0:
+ return im + "i"
+ case sim == 0:
+ return re
+ case sim < 0:
+ return fmt.Sprintf("(%s%si)", re, im)
+ default:
+ return fmt.Sprintf("(%s+%si)", re, im)
}
- return re + "+" + im + "i"
}