Skip to content

fix(sensors): kelvin to Celsius#1997

Merged
shirou merged 1 commit intoshirou:masterfrom
Aoang:fix/kelvin-to-celsius
Jan 29, 2026
Merged

fix(sensors): kelvin to Celsius#1997
shirou merged 1 commit intoshirou:masterfrom
Aoang:fix/kelvin-to-celsius

Conversation

@Aoang
Copy link
Copy Markdown
Contributor

@Aoang Aoang commented Jan 26, 2026

The previous implementation was incorrect
when temp = 2732, expected 0.05, got -0.14

@Aoang Aoang force-pushed the fix/kelvin-to-celsius branch from 22ccafc to 2f20a06 Compare January 26, 2026 08:21
@Aoang Aoang marked this pull request as draft January 26, 2026 08:30
@Aoang Aoang force-pushed the fix/kelvin-to-celsius branch from 2f20a06 to 299e9cc Compare January 26, 2026 08:35
@Aoang Aoang marked this pull request as ready for review January 26, 2026 08:35
@Aoang Aoang force-pushed the fix/kelvin-to-celsius branch from 299e9cc to cd02b13 Compare January 26, 2026 08:38
The previous implementation was incorrect
when temp = 2732, expected 0.05, got -0.14
@Aoang Aoang force-pushed the fix/kelvin-to-celsius branch from cd02b13 to 01bdbba Compare January 26, 2026 08:39
Copy link
Copy Markdown
Owner

@shirou shirou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! According to the document, WMI returns "tenths of degrees Kelvin", so the correct formula is temp / 10 - 273.15.

But since temp is uint32, temp/10 performs integer division and loses precision. This PR avoids that by using (temp*10 - 27315) / 100, which is mathematically equivalent but keeps everything in integers before the final division. And it also makes the code simpler. Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants