Open d1msk1y opened 6 days ago
this is kind of the limitation of floating point numbers. I do not think that we could do anything about it.
I do not think that the library should handle those imprecision. Furthermore I think the library should not round floating point values at all.
How are these imprecision limiting you right now?
In payload decode in sgr_encode, all values, even the float ones, are converted to int: https://github.com/SmartGridready/SGrPython/blob/b838830850a0643f24849d567e9f13de69ef0b2b/sgr_library/payload_decoder.py#L95
Of course, I tried removing the rounding for the float cases, which did resolve the issue, however the written float values, when read, are not as precise, as they are before the encoding.
For example: With now resolved float to int conversion, when I write
3.6
, I get3.5999999046325684
when I try to read it with datapoint.read() https://github.com/SmartGridready/SGrPython/blob/b838830850a0643f24849d567e9f13de69ef0b2b/sgr_library/modbus_interface.py#L47 As far as I know, this behavior is common for float values, due to the way they are built, as they don't always truly represent the exact decimal valueSo the best solution I have came up with so far, is simply rounding the precise digits
However, this way we have some limitations regarding the precision of the value