num: replace bytes.Buffer with strings.Builder for format construction

This commit is contained in:
Dan Kortschak
2019-02-26 11:49:37 +10:30
parent 15d355e1cb
commit 97c2038886
4 changed files with 7 additions and 16 deletions

View File

@@ -5,9 +5,9 @@
package dual
import (
"bytes"
"fmt"
"math"
"strings"
)
// Number is a float64 precision dual number.
@@ -52,9 +52,7 @@ func (d Number) Format(fs fmt.State, c rune) {
// This is horrible, but it's what we have.
func fmtString(fs fmt.State, c rune, prec, width int, wantPlus bool) string {
// TODO(kortschak) Replace this with strings.Builder
// when go1.9 support is dropped from Gonum.
var b bytes.Buffer
var b strings.Builder
b.WriteByte('%')
for _, f := range "0+- " {
if fs.Flag(int(f)) || (f == '+' && wantPlus) {

View File

@@ -5,8 +5,8 @@
package dualquat
import (
"bytes"
"fmt"
"strings"
"gonum.org/v1/gonum/num/dual"
"gonum.org/v1/gonum/num/quat"
@@ -59,9 +59,7 @@ func (d Number) Format(fs fmt.State, c rune) {
// This is horrible, but it's what we have.
func fmtString(fs fmt.State, c rune, prec, width int, wantPlus bool) string {
// TODO(kortschak) Replace this with strings.Builder
// when go1.9 support is dropped from Gonum.
var b bytes.Buffer
var b strings.Builder
b.WriteByte('%')
for _, f := range "0+- " {
if fs.Flag(int(f)) || (f == '+' && wantPlus) {

View File

@@ -5,9 +5,9 @@
package hyperdual
import (
"bytes"
"fmt"
"math"
"strings"
)
// Number is a float64 precision hyperdual number.
@@ -55,9 +55,7 @@ func (d Number) Format(fs fmt.State, c rune) {
// This is horrible, but it's what we have.
func fmtString(fs fmt.State, c rune, prec, width int, wantPlus bool) string {
// TODO(kortschak) Replace this with strings.Builder
// when go1.9 support is dropped from Gonum.
var b bytes.Buffer
var b strings.Builder
b.WriteByte('%')
for _, f := range "0+- " {
if fs.Flag(int(f)) || (f == '+' && wantPlus) {

View File

@@ -5,7 +5,6 @@
package quat
import (
"bytes"
"fmt"
"strconv"
"strings"
@@ -53,9 +52,7 @@ func (q Number) Format(fs fmt.State, c rune) {
// This is horrible, but it's what we have.
func fmtString(fs fmt.State, c rune, prec, width int, wantPlus bool) string {
// TODO(kortschak) Replace this with strings.Builder
// when go1.9 support is dropped from Gonum.
var b bytes.Buffer
var b strings.Builder
b.WriteByte('%')
for _, f := range "0+- " {
if fs.Flag(int(f)) || (f == '+' && wantPlus) {