Skip to content
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 float to byte conversion. #547

Merged
merged 1 commit into from
Sep 25, 2021
Merged

Fix float to byte conversion. #547

merged 1 commit into from
Sep 25, 2021

Conversation

Rem0o
Copy link
Contributor

@Rem0o Rem0o commented Sep 24, 2021

The conversion was using an implicit double between the float value to the byte value, which cause some issue with a software value of 100f, which resulted to 254 instead of 255.

Extracted the conversion as a function.

The problem simplified:

float floatValue = 100f;
float byteValue = floatValue * 2.55f;

// 254
byte a = (byte)((floatValue * 2.55f));
// 255
byte b = (byte)(byteValue);

// false
Console.WriteLine(a == b);

The conversion was using a double between the float value to the byte value, which cause some issue with a software value of 100f, which resulted to 254 instead of 255.

Extracted as a function.
@PhyxionNL PhyxionNL merged commit 38162b5 into LibreHardwareMonitor:master Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants