Creates a new quantized float decoder based on given field
(bitCount, flags *int32, lowValue, highValue *float32)
| 145 | |
| 146 | // Creates a new quantized float decoder based on given field |
| 147 | func newQuantizedFloatDecoder(bitCount, flags *int32, lowValue, highValue *float32) *quantizedFloatDecoder { |
| 148 | qfd := &quantizedFloatDecoder{} |
| 149 | |
| 150 | // Set common properties |
| 151 | if *bitCount == 0 || *bitCount >= 32 { |
| 152 | qfd.NoScale = true |
| 153 | qfd.Bitcount = 32 |
| 154 | return qfd |
| 155 | } else { |
| 156 | qfd.NoScale = false |
| 157 | qfd.Bitcount = uint32(*bitCount) |
| 158 | qfd.Offset = 0.0 |
| 159 | |
| 160 | if lowValue != nil { |
| 161 | qfd.Low = *lowValue |
| 162 | } else { |
| 163 | qfd.Low = 0.0 |
| 164 | } |
| 165 | |
| 166 | if highValue != nil { |
| 167 | qfd.High = *highValue |
| 168 | } else { |
| 169 | qfd.High = 1.0 |
| 170 | } |
| 171 | } |
| 172 | if flags != nil { |
| 173 | qfd.Flags = uint32(*flags) |
| 174 | } else { |
| 175 | qfd.Flags = 0 |
| 176 | } |
| 177 | |
| 178 | // Validate flags |
| 179 | qfd.validateFlags() |
| 180 | |
| 181 | // Handle Round Up, Round Down |
| 182 | steps := (1 << uint(qfd.Bitcount)) |
| 183 | |
| 184 | Range := float32(0) |
| 185 | if (qfd.Flags & qff_rounddown) != 0 { |
| 186 | Range = qfd.High - qfd.Low |
| 187 | qfd.Offset = (Range / float32(steps)) |
| 188 | qfd.High -= qfd.Offset |
| 189 | } else if (qfd.Flags & qff_roundup) != 0 { |
| 190 | Range = qfd.High - qfd.Low |
| 191 | qfd.Offset = (Range / float32(steps)) |
| 192 | qfd.Low += qfd.Offset |
| 193 | } |
| 194 | |
| 195 | // Handle integer encoding flag |
| 196 | if (qfd.Flags & qff_encode_integers) != 0 { |
| 197 | delta := qfd.High - qfd.Low |
| 198 | |
| 199 | if delta < 1 { |
| 200 | delta = 1 |
| 201 | } |
| 202 | |
| 203 | deltaLog2 := math.Ceil(math.Log2(float64(delta))) |
| 204 | Range2 := (1 << uint(deltaLog2)) |
no test coverage detected