Quantize a float
(val float32)
| 108 | |
| 109 | // Quantize a float |
| 110 | func (qfd *quantizedFloatDecoder) quantize(val float32) float32 { |
| 111 | if val < qfd.Low { |
| 112 | if (qfd.Flags & qff_roundup) == 0 { |
| 113 | _panicf("Field tried to quantize an out of range value") |
| 114 | } |
| 115 | |
| 116 | return qfd.Low |
| 117 | } else if val > qfd.High { |
| 118 | if (qfd.Flags & qff_rounddown) == 0 { |
| 119 | _panicf("Field tried to quantize an out of range value") |
| 120 | } |
| 121 | |
| 122 | return qfd.High |
| 123 | } |
| 124 | |
| 125 | i := uint32((val - qfd.Low) * qfd.HighLowMul) |
| 126 | return qfd.Low + (qfd.High-qfd.Low)*(float32(i)*qfd.DecMul) |
| 127 | } |
| 128 | |
| 129 | // Actual float decoding |
| 130 | func (qfd *quantizedFloatDecoder) decode(r *reader) float32 { |
no test coverage detected