SmartPascal
IsNaN
Function
Checks to see if a floating point number holds a real number Math unit
 function IsNaN ( const Float : Single | Double | Extended ) : Boolean;
Description
The IsNaN function returns True if the Float parameter is Not a number.
 
A floating point number can be set to such a value when it is assigned an undetermined value. The standard is :
 
NAN = 0.0 / 0.0
Related commands
Infinity Floating point value of infinite size
IsInfinite Checks whether a floating point number is infinite
NaN Not a real number
 
Example code : Assign NAN to a number and then test using IsNaN
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  Math,   // Unit containing the IsNaN command
  SysUtils,
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  float : Double;

begin
  // Set the number to an invalid number
  float := NAN;     // Equivalent to 0.0/0.0

  // Although an invalid number, we can still display it
  ShowMessage('float = '+FloatToStr(float));

  // And we can test to see if it is a valid number
  if IsNaN(float)
  then ShowMessage('float is not a number')
  else ShowMessage('float = '+FloatToStr(float));
end;
 
end.
Hide full unit code
   float = NAN
   float is not a number