unsigned long dfactor = 1000;
unsigned long zfactor = 100;
unsigned long speedOfSoundAt0C = 3315UL * zfactor;
// 123456
// 200000 µm * 1000 = 200_000_000
// 1234567890
// 4294967296
unsigned long distance = 200000UL * dfactor;
unsigned long travelTime = 584UL;
unsigned long temperature = 0;
float FspeedOfSoundAt0C = 331.5;
float Fdistance = 0.2;
float FtravelTime = 584.0 / 1000000;
float Ftemperature = 0.0;
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
temperature = ( ( (distance ) / travelTime) - (speedOfSoundAt0C) ) * 10 / 6;
Serial.print("integer-calc temperature=");
Serial.println(temperature / 1000.0,6);
Ftemperature = ( (Fdistance/ FtravelTime - FspeedOfSoundAt0C) * 10.0 ) / 6.0;
Serial.print("float-calc Ftemperature=");
Serial.println(Ftemperature,6);
FtravelTime = 580.0 / 1000000;
Ftemperature = ( (Fdistance/ FtravelTime - FspeedOfSoundAt0C) * 10.0 ) / 6.0;
Serial.print("float-calc 4 µsec too short Ftemperature=");
Serial.println(Ftemperature,6);
FtravelTime = 588.0 / 1000000;
Ftemperature = ( (Fdistance/ FtravelTime - FspeedOfSoundAt0C) * 10.0 ) / 6.0;
Serial.print("float-calc 4 µsec too long Ftemperature=");
Serial.println(Ftemperature,6);
}
void loop() {
// put your main code here, to run repeatedly:
}