Recent

Author Topic: [SOLVED] IsNan(double) gives compiler error  (Read 289 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 279
[SOLVED] IsNan(double) gives compiler error
« 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?
« Last Edit: April 21, 2021, 12:44:14 pm by trev »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 862
Re: IsNan(double) gives compiler error
« Reply #1 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).
« Last Edit: April 21, 2021, 10:16:06 am by Jonas Maebe »

wp

  • Hero Member
  • *****
  • Posts: 8388
Re: IsNan(double) gives compiler error
« Reply #2 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.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

mtanner

  • Sr. Member
  • ****
  • Posts: 279
Re: IsNan(double) gives compiler error
« Reply #3 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.

Thaddy

  • Hero Member
  • *****
  • Posts: 10782
Re: IsNan(double) gives compiler error
« Reply #4 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.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 862
Re: [SOLVED] IsNan(double) gives compiler error
« Reply #5 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.

wp

  • Hero Member
  • *****
  • Posts: 8388
Re: IsNan(double) gives compiler error
« Reply #6 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;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018