Skip to content

Commit a0f85a8

Browse files
committed
Add a description to celsiusToRaw
1 parent 346ac7f commit a0f85a8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

DallasTemperature.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,17 @@ float DallasTemperature::rawToCelsius(int16_t raw) {
745745

746746
}
747747

748-
// convert from Celsius to raw
748+
// Convert from Celsius to raw returns temperature in raw integer format.
749+
// The rounding error in the conversion is smaller than 0.01°C
750+
// where the resolution of the sensor is at best 0.0625°C (in 12 bit mode).
751+
// Rounding error can be verified by running:
752+
// for (float t=-55.; t<125.; t+=0.01)
753+
// {
754+
// Serial.println( DallasTemperature::rawToCelsius(DallasTemperature::celsiusToRaw(t))-t, 4 );
755+
// }
749756
int16_t DallasTemperature::celsiusToRaw(float celsius) {
750757

751-
return static_cast<uint16_t>( celsius * 128.f ); //this just discards of the decimal part (rounds towards zero)
758+
return static_cast<uint16_t>( celsius * 128.f );
752759
}
753760

754761
// convert from raw to Fahrenheit

0 commit comments

Comments
 (0)