Math abs function does not work with double?

Hi,

I am working with precise numbers. I have noticed that the abs function, does not work correctly.

void setup() {
  Serial.begin(115200);
}

void loop() {
  double number = 0.000000029166328080224515062468;
  double number2 = abs(number);
  Serial.println(number, 30);
  Serial.println(number2, 30);
  delay(1000);
}

Outputs
0.000000029166328080224520391539
0.000000000000000000000000000000

Is it possible that double has 64 bit, and the abs function is good only for 32 bit numbers?

Thanks!

abs is an integer function. Try fabs. That works on doubles.

5 Likes

Thank you! Did not know that!

1 Like