Lazarus

Free Pascal => General => Topic started by: mtanner on April 21, 2021, 09:55:43 am

Title: [SOLVED] IsNan(double) gives compiler error
Post by: mtanner on April 21, 2021, 09:55:43 am
I have a procedure
MyProc(X:double);
and inside MyProc I code
 If IsNan(X) then Exit;

but the compiler gives an error saying that IsNan expects a TDoublePoint argument. I think this must be a bug, else how can I test for X being Nan?
Title: Re: IsNan(double) gives compiler error
Post by: Jonas Maebe on April 21, 2021, 09:57:52 am
There is no declaration for a TDoublePoint type in the FPC sources. You must have included another unit that declares this type and an "IsNan" function with that parameter type, and that's missing an "overload" directive (so the compiler doesn't keep searching for other overloads in other units).
Title: Re: IsNan(double) gives compiler error
Post by: wp on April 21, 2021, 10:16:00 am
TAChart has an overload of IsNaN. If you have TAChartUtils in your uses clause, but not Math, your program will only find the overload for TDoublePoint. So, add Math to "uses" to solve the issue.
Title: Re: IsNan(double) gives compiler error
Post by: mtanner on April 21, 2021, 10:29:22 am
Yes I have TAChartUtils in the Uses, but not Math. Put Math in and it now works ok.
Thanks.
Title: Re: IsNan(double) gives compiler error
Post by: Thaddy on April 21, 2021, 01:12:33 pm
TAChart has an overload of IsNaN. If you have TAChartUtils in your uses clause, but not Math, your program will only find the overload for TDoublePoint. So, add Math to "uses" to solve the issue.
Why? NaN is NaN. This baffles me....Overloading IsNan can never be correct.
Title: Re: [SOLVED] IsNan(double) gives compiler error
Post by: Jonas Maebe on April 21, 2021, 01:59:30 pm
This is TDoublePoint:
Code: [Select]
  TDoublePoint = record
    X, Y: Double;
  end;
So yes, if you want to have an IsNan function that works with it, you need an overload.
Title: Re: IsNan(double) gives compiler error
Post by: wp on April 21, 2021, 02:31:41 pm
TAChart has an overload of IsNaN. If you have TAChartUtils in your uses clause, but not Math, your program will only find the overload for TDoublePoint. So, add Math to "uses" to solve the issue.
Why? NaN is NaN. This baffles me....Overloading IsNan can never be correct.
Why? Whats's wrong with this?
Code: Pascal  [Select][+][-]
  1. type
  2.   TDoublePoint = record
  3.     X, Y: Double;
  4.   end;
  5.  
  6. function IsNan(const APoint: TDoublePoint): Boolean;     // overload; (of course)
  7. begin
  8.   Result := IsNan(APoint.X) or IsNan(APoint.Y);
  9. end;
TinyPortal © 2005-2018