Undefined values: Difference between revisions

(→‎{{header|jq}}: {}["key"] yields null)
(→‎{{header|GAP}}: Add Fortran)
Line 285:
Member_2 is undefined true
</pre>
 
=={{header|Fortran}}==
Older style Fortran had no inbuilt facilities, other than a programmer adding code to recognise certain special values as "no value" or similar, so a set of valid values might be 1:20, and zero was reserved to signify "bad", or for a three-digit data field the special value 999 might be recognised, etc. Mistakes and confusions were routine, since a six-digit field might require 999999 except that value is too big for sixteen-bit integers and as a floating-point value may not be exactly expressed in binary. Averaging such values without checking for 999 (or 999999, etc.) might lead to overflow in output data fields or bad results that might be detected before publishing a report. In ''Numerical Methods That Work - Usually'', F.S. Acton remarks "The person who encoded YES, NO, DON'T CARE as one, two, three, ''respectively'' got the sort of correlations she deserved."
 
A more flexible approach involves associating a state variable with a monitored variable, thus X to hold the value, and XGOOD the indicator - as before, tedious added code.
 
More modern Fortrans recognise the NaN state of floating-point variables on computers whose floating-point arithmetic follows the IEEE standard, via the logical function
<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|GAP}}==
1,220

edits