Login Page - Create Account

Support Board


Date/Time: Sun, 23 Feb 2025 13:46:40 +0000



[Programming Help] - compare two floating points

View Count: 673

[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
[2021-02-12 12:42:19]
User907968 - Posts: 833
Remove the long from the following -
long float diff = fabs(f1 - f2);

long float is not a built-in type in c++ - https://en.cppreference.com/w/cpp/language/types
[2021-02-12 16:24:45]
norvik_ - Posts: 106
Hi, for price comparison inside your SC studies better to use built-in sc.FormattedEvaluate function.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account