-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix various issues with handling of floating values within the LWM2M subsystem #16154
Comments
@mike-scott, same question as before; wonder if this is still applicable, and, if so, if it could be addressed for 2.0 |
Thank you for the reminder. I will address. |
Just asking if this has this already been addressed, @mike-scott - few LWM2M Pr were merged lately.. |
@lodup29 @ioannisg I've setup a PR which addresses the first 3 items (and a few other bugs), however item 4 in the table above:
Is actually not a bug, but reflects a conversion issue going from fixed formatting to binary float format. This can be reproduced using the following website: Enter "0.05" in the Decimal to Binary section at the top, and then click "Convert" Copy that binary value into the Binary to Decimal section below and then click "Convert" NOTE: Tool truncates infinite binary fractions to 62 bits. I'm using less than that so value is truncated earlier. |
Formatting a float32/64 value for plain text is broken. Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5 Current formatter was using %d.%d (%lld.%lld for 64bit) so exported value was 0.500000 (or 0.5) To fix this, for val2 use a zero-padded formatter for the maximum length of each bit length (6 for 32bit and 9 for 64bit), and then remove the zero characters at the end of the string. Notes re: handling of val1/val2 signs: - eliminate potential negative sign when converting val2 to avoid: a value like: 0.-5 - use negative val2 when val1 is 0 to fix small negative handling such as -0.5 Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
Current JSON formatting for float32/64 is broken in a similar way as plain text. Let's use the newly fixed logic for plain text to generate the float32/64 values in the JSON string. Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
When val1 is 0, we need to handle a negative val2 value so that we generate correct TLV value. Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal. Currently we generate: 0.5 (losing the sign). Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
Formatting a float32/64 value for plain text is broken. Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5 Current formatter was using %d.%d (%lld.%lld for 64bit) so exported value was 0.500000 (or 0.5) To fix this, for val2 use a zero-padded formatter for the maximum length of each bit length (6 for 32bit and 9 for 64bit), and then remove the zero characters at the end of the string. Notes re: handling of val1/val2 signs: - eliminate potential negative sign when converting val2 to avoid: a value like: 0.-5 - use negative val2 when val1 is 0 to fix small negative handling such as -0.5 Fixes: #16154 Signed-off-by: Michael Scott <mike@foundries.io>
Current JSON formatting for float32/64 is broken in a similar way as plain text. Let's use the newly fixed logic for plain text to generate the float32/64 values in the JSON string. Fixes: #16154 Signed-off-by: Michael Scott <mike@foundries.io>
When val1 is 0, we need to handle a negative val2 value so that we generate correct TLV value. Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal. Currently we generate: 0.5 (losing the sign). Fixes: #16154 Signed-off-by: Michael Scott <mike@foundries.io>
Formatting a float32/64 value for plain text is broken. Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5 Current formatter was using %d.%d (%lld.%lld for 64bit) so exported value was 0.500000 (or 0.5) To fix this, for val2 use a zero-padded formatter for the maximum length of each bit length (6 for 32bit and 9 for 64bit), and then remove the zero characters at the end of the string. Notes re: handling of val1/val2 signs: - eliminate potential negative sign when converting val2 to avoid: a value like: 0.-5 - use negative val2 when val1 is 0 to fix small negative handling such as -0.5 Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
Current JSON formatting for float32/64 is broken in a similar way as plain text. Let's use the newly fixed logic for plain text to generate the float32/64 values in the JSON string. Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
When val1 is 0, we need to handle a negative val2 value so that we generate correct TLV value. Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal. Currently we generate: 0.5 (losing the sign). Fixes: zephyrproject-rtos#16154 Signed-off-by: Michael Scott <mike@foundries.io>
Describe the bug
However only the sign of val1 is considered for TLV while the JSON representation simply formats the value as ("%d.%d",lFloatValue.val1, lFloatValue.val2) ("0.-500000") thus resulting in an exception when attempting to parse the value on the other side.
However as previously stated the value will simply end up being formated as ("%d.%d",lFloatValue.val1, lFloatValue.val2) ("0.500000" instead of "0.050000")
To Reproduce
The text was updated successfully, but these errors were encountered: