milesburton / Arduino-Temperature-Control-Library

Arduino Temperature Library
https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library
969 stars 487 forks source link

Use float for calculations between Fahrenheit and Celcius #172

Closed dirkmueller closed 4 years ago

dirkmueller commented 4 years ago

The result of these calculations is stored in float, which in the case of 32bit wide floats has 5 digits of accuracy. this is enough for the purpose. Without this change, the calculations are performed promoted and performed in double precision, which is very inefficient on some platforms that do not have support for hardware based double floating point.

RobTillaart commented 4 years ago

Looks good to me.

@dirkmueller
Do you have a particular platform in mind where this promoting happens? (As I have quite some libraries this is interesting for me)

milesburton commented 4 years ago

From a contributor: "it gets promoted because your literals are doubles so that widens the expression value. It's the C++ compiler doing it."