File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,24 @@ func (n *Number) isExactInt() bool {
314
314
return bits .TrailingZeros64 (mant ) >= mBits - exp
315
315
}
316
316
317
+ // CoerceFloat returns the number as a float64.
318
+ // If the number is an integer, it will be
319
+ // converted to a float64 with the closest representation.
320
+ func (n * Number ) CoerceFloat () float64 {
321
+ switch n .typ {
322
+ case IntType :
323
+ return float64 (int64 (n .bits ))
324
+ case UintType :
325
+ return float64 (n .bits )
326
+ case Float32Type :
327
+ return float64 (math .Float32frombits (uint32 (n .bits )))
328
+ case Float64Type :
329
+ return math .Float64frombits (n .bits )
330
+ default :
331
+ return 0.0
332
+ }
333
+ }
334
+
317
335
// Msgsize implements msgp.Sizer
318
336
func (n * Number ) Msgsize () int {
319
337
switch n .typ {
You can’t perform that action at this time.
0 commit comments