github.com/searKing/golang/go@v1.2.74/encoding/prettyjson/float.go (about) 1 // Copyright 2023 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package prettyjson 6 7 import ( 8 "math" 9 "strconv" 10 ) 11 12 func appendFloat(out []byte, n float64, bitSize int) []byte { 13 switch { 14 case math.IsNaN(n): 15 return append(out, "nan"...) 16 case math.IsInf(n, +1): 17 return append(out, "inf"...) 18 case math.IsInf(n, -1): 19 return append(out, "-inf"...) 20 default: 21 return strconv.AppendFloat(out, n, 'g', -1, bitSize) 22 } 23 }