Undefined values: Difference between revisions

Added FreeBASIC
No edit summary
(Added FreeBASIC)
Line 299:
<lang Fortran>IsNaN(x)</lang>
This is the only safe way to detect them as tests to detect the special behaviour of NaN states such as ''if x = x then...else aha!;'' might be optimised away by the compiler, and other tests may behave oddly. For instance x ¬= 0 might be compiled as ¬(x = 0) and the special NaN behaviour will not be as expected. Such NaN values can come via READ statements, because "NaN" is a recognised numerical input option, and could be used instead of "999" in a F3.0 data field, etc. Or, your system's input processing might recognise "?" or other special indicators and so on.
 
=={{header|FreeBASIC}}==
In FreeBASIC all variables are given a default value (zero for numbers, false for boolean and empty for strings) when they are declared unless they are assigned a different value at that time or are specifically left uninitialized (using the 'Any' keyword). If the latter are used before they have been initialized, then they will contain a 'garbage' value i.e. whatever value happens to be in the associated memory:
<lang freebasic>' FB 1.05.0 Win64
 
Dim i As Integer '' initialized to 0 by default
Dim j As Integer = 3 '' initialized to 3
Dim k As Integer = Any '' left uninitialized (compiler warning but can be ignored)
 
Print i, j, k
Sleep</lang>
 
{{out}}
Sample output (fortuitously, k contained its default value of 0 on this run):
<pre>
0 3 0
</pre>
 
=={{header|GAP}}==
9,476

edits