X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=libgo%2Fgo%2Fstrconv%2Fftoa.go;h=e1ea0a350383d46b84b76443557e16f3248740c9;hp=8342b6abe79494db82e085a377396e3479518c6b;hb=7da93e24295c8b313ecdcedee0b8bde70b335e61;hpb=f86a7907050666ce7cab2890b353619f83d6c98b diff --git a/libgo/go/strconv/ftoa.go b/libgo/go/strconv/ftoa.go index 8342b6abe79..e1ea0a35038 100644 --- a/libgo/go/strconv/ftoa.go +++ b/libgo/go/strconv/ftoa.go @@ -22,8 +22,10 @@ type floatInfo struct { var float32info = floatInfo{23, 8, -127} var float64info = floatInfo{52, 11, -1023} -// Ftoa32 converts the 32-bit floating-point number f to a string, -// according to the format fmt and precision prec. +// FormatFloat converts the floating-point number f to a string, +// according to the format fmt and precision prec. It rounds the +// result assuming that the original was obtained from a floating-point +// value of bitSize bits (32 for float32, 64 for float64). // // The format fmt is one of // 'b' (-ddddp±ddd, a binary exponent), @@ -43,24 +45,17 @@ var float64info = floatInfo{52, 11, -1023} // Ftoa32(f) is not the same as Ftoa64(float32(f)), // because correct rounding and the number of digits // needed to identify f depend on the precision of the representation. -func Ftoa32(f float32, fmt byte, prec int) string { - return genericFtoa(uint64(math.Float32bits(f)), fmt, prec, &float32info) -} - -// Ftoa64 is like Ftoa32 but converts a 64-bit floating-point number. -func Ftoa64(f float64, fmt byte, prec int) string { +func FormatFloat(f float64, fmt byte, prec int, n int) string { + if n == 32 { + return genericFtoa(uint64(math.Float32bits(float32(f))), fmt, prec, &float32info) + } return genericFtoa(math.Float64bits(f), fmt, prec, &float64info) } -// FtoaN converts the 64-bit floating-point number f to a string, -// according to the format fmt and precision prec, but it rounds the -// result assuming that it was obtained from a floating-point value -// of n bits (32 or 64). -func FtoaN(f float64, fmt byte, prec int, n int) string { - if n == 32 { - return Ftoa32(float32(f), fmt, prec) - } - return Ftoa64(f, fmt, prec) +// AppendFloat appends the string form of the floating-point number f, +// as generated by FormatFloat, to dst and returns the extended buffer. +func AppendFloat(dst []byte, f float64, fmt byte, prec int, n int) []byte { + return append(dst, FormatFloat(f, fmt, prec, n)...) } func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {