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)
| 314 | // |
| 315 | // NOTE: this will panic on NaN, +/-inf |
| 316 | func 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 | |
| 325 | func newFromFloat(val float64, bits uint64, flt *floatInfo) Decimal { |
| 326 | if math.IsNaN(val) || math.IsInf(val, 0) { |
searching dependent graphs…