Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By xtal
#41325 I think this is a problem .... If not please explain why?
8/3600 = 0.00222222222222222 I trying to print 6 decimals, but print 0.000000
If I do 3600/8 then print the reciprical I get 0.002222

Code: Select allint RFH = 8;
float Hr = 0;
double yy = 0;
float zz = 0; 

void setup() {
 Serial.begin(38400);                            //  start serial for debug
  delay(10);
}
void loop() {
 delay(1000);
  Serial.print("Value RFH= ");
  Serial.println(RFH);
  Serial.println("Compute RFH/3600 then Serial.print(value,6) sb 0.002222");
  zz = RFH/3600 ;                      // Arduino 5 decimals  8/3600=.00222
  Serial.print("Computed zz = RFH/3600 = ");
  Serial.println(zz,6);
  yy = RFH/3600;
  Serial.print("Computed RFH/3600 Double = ");
  Serial.println(yy,6);
  Serial.println("Compute zz=3600/RFH then zz=1/zz then Serial.print(zz,6) sb 0.002222");
  zz=3600/RFH; zz=1/zz;
  Serial.print("Computed Reciprical = ");
  Serial.println(zz,6); 
}



PORT OPEN 38400
Value RFH= 8
Compute RFH/3600 then Serial.print(value,6) sb 0.002222
Computed zz = RFH/3600 = 0.000000
Computed RFH/3600 Double = 0.000000
Compute zz=3600/RFH then zz=1/zz then Serial.print(zz,6) sb 0.002222
Computed Reciprical = 0.002222
Value RFH= 8
Compute RFH/3600 then Serial.print(value,6) sb 0.002222
Computed zz = RFH/3600 = 0.000000
Computed RFH/3600 Double = 0.000000
Compute zz=3600/RFH then zz=1/zz then Serial.print(zz,6) sb 0.002222
Computed Reciprical = 0.002222
Value RFH= 8
Compute RFH/3600 then Serial.print(value,6) sb 0.002222
Computed zz = RFH/3600 = 0.000000
Computed RFH/3600 Double = 0.000000
Compute zz=3600/RFH then zz=1/zz then Serial.print(zz,6) sb 0.002222
Computed Reciprical = 0.002222

PORT CLOSED
User avatar
By picstart
#41359 Not a bug.
Humans use base ten and handheld calculators use BCD so they also compute in a simulated binary version of base ten mathematics. This can often lead the unaware into concluding that a purely binary device gets the wrong answer.
The esp8266 is a binary (base two) device so notational differences in base conversion is expected and is valid mathematics. The calculations are correct in base two but base conversion causes notational issues. With a large amount of precision ( multiple large binary registers) the notational differences can be held to small variations in the nth decimal place.
This issue has been asked and answered in an earlier thread.