If your original data has negative values, then a zero point can offset the range, allowing you to store them in an unsigned integer. So if your zero point was 128, then unscaled negative values -127 to -1 could be represented by 1 to 127, and positive values 0 to 127 could be represented by 128 to 255. Note the quantized value of 0 (or input -128 here) is intentionally unused to keep range symmetry on both ends, hence a total range of 256-1 values instead of 256.
e.g. Given an input tensor with data ranging from -1000 to +1000 (inclusive both ends), and an element in it with value 39.215686275, that element's quantized value would be 133 when using 128 as the zero point:
quantizedValue = round(realValue / scale + zeroPoint)
quantizedValue = round(39.215686275 / 7.843137255 + 128) = 133
quantizedValue = round(0 / 7.843137255 + 128) = 128
quantizedValue = round(1000 / 7.843137255 + 128) = 255
quantizedValue = round(-1000 / 7.843137255 + 128) = 1
Where:
zeroPoint = 128 ## Note 256/2 is symmetric, and q=0 isn't really used.
## Use same zero point for entire tensor.
scale = (realRangeMaxValue - realRangeMinValue) / quantizedRange
scale = (1000 - -1000) / 255 = 7.843137255
## Alternately could use inverse scale and multiply above, inverseScale = 0.1275
realRangeMinValue = -1000
realRangeMaxValue = 1000
quantizedRange = 2^8 - 1 = 255
quantizedRangeMinValue = integerRangeMinValue - zeroPoint = -128
quantizedRangeMaxValue = integerRangeMaxValue - zeroPoint = 127
Conversely:
realValue = (quantizedValue - zeroPoint) * scale
realValue = (133 - 128) * 7.843137255 = 39.215686275
realValue = (128 - 128) * 7.843137255 = 0
realValue = (255 - 128) * 7.843137255 = 1000
realValue = (1 - 128) * 7.843137255 = -1000