OK. Thanks for your reply.Float numbers are imprecise; probably the result of 0.1 + -0.1 is ever-so-slightly negative because of effectively a binary rounding error. Your print will round that number down to two digits after the decimal, so you get the 'weird' -0.00 result.
Search found 2 matches
- Mon Jul 01, 2024 11:31 pm
- Forum: Report Bugs
- Topic: Math problem in ESP32?
- Replies: 2
- Views: 12801
Re: Math problem in ESP32?
- Sat Jun 29, 2024 9:46 pm
- Forum: Report Bugs
- Topic: Math problem in ESP32?
- Replies: 2
- Views: 12801
Math problem in ESP32?
Hello. Why when performing the following mathematical operation with float, the result is -0.0?
I don't make sense of the "-" sign. Is it a bug?
In the following code you can see the result:
float val1 = -0.1;
float val2;
void setup(){
Serial.begin(115200);
}
void loop(){
val2 = val1 + 0.1 ...
I don't make sense of the "-" sign. Is it a bug?
In the following code you can see the result:
float val1 = -0.1;
float val2;
void setup(){
Serial.begin(115200);
}
void loop(){
val2 = val1 + 0.1 ...