Login Page - Create Account

Support Board


Date/Time: Sun, 23 Feb 2025 13:19:52 +0000



Post From: compare two floating points

[2021-02-12 11:49:10]
User61576 - Posts: 445
I have the following function to compare two floating points

int compare(float f1, float f2)
{
  float epsilon = 0.00001;
  long float diff = fabs(f1 - f2);
  if (diff < epsilon) return 0;
  else if (f1 > f2) return 1;
  else return - 1;
}

but when compiling I get an error:
In function 'int compare(float, float)':
error: 'long' specified with 'float'
60 | long float diff = fabs(f1 - f2);

This used to work in the past and if anyone has any idea what I am doing wrong here I will be happy to get an advice
Thanks!
Date Time Of Last Edit: 2021-02-12 11:49:27