MCPcopy
hub / github.com/shopspring/decimal / NewFromFloat32

Function NewFromFloat32

decimal.go:316–323  ·  view source on GitHub ↗

NewFromFloat32 converts a float32 to Decimal. The converted number will contain the number of significant digits that can be represented in a float with reliable roundtrip. This is typically 6-8 digits depending on the input. See https://www.exploringbinary.com/decimal-precision-of-binary-floating-

(value float32)

Source from the content-addressed store, hash-verified

314//
315// NOTE: this will panic on NaN, +/-inf
316func NewFromFloat32(value float32) Decimal {
317 if value == 0 {
318 return New(0, 0)
319 }
320 // XOR is workaround for https://github.com/golang/go/issues/26285
321 a := math.Float32bits(value) ^ 0x80808080
322 return newFromFloat(float64(value), uint64(a)^0x80808080, &float32info)
323}
324
325func newFromFloat(val float64, bits uint64, flt *floatInfo) Decimal {
326 if math.IsNaN(val) || math.IsInf(val, 0) {

Callers 3

TestNewFromFloat32RandomFunction · 0.85
TestNewFromFloat32QuickFunction · 0.85
ExampleNewFromFloat32Function · 0.85

Calls 2

NewFunction · 0.85
newFromFloatFunction · 0.85

Tested by 3

TestNewFromFloat32RandomFunction · 0.68
TestNewFromFloat32QuickFunction · 0.68
ExampleNewFromFloat32Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…