I have a Mathematica expression that is mapped onto an external C
function via MathLink
. The external function passes a double
array (using MLPutReal64List[]
), which Mathematica interprets as a list of Real
's. Sometimes the external function sends values for which the C
math library function isnan(value)
returns 1
(say from division by zero, or log(0)
). Mathematica reads these values as NaN`
. For example,
In[1]:= result = externalFunction[<some input>]
Out[1]= {NaN`, 0.18225}
Evaluating {NaN`, 0.182255} gives a syntax error:
In[2]:= {NaN`, 0.182255}
Syntax::tsntxi: "{NaN`,0.182255}" is incomplete; more input is needed.
Syntax::sntxi: Incomplete expression; more input is needed.
which makes sense, since a variable name is expected to follow the `
, giving some variable in the NaN
context.
But mathematica accepts result[[1]]
as a number:
In[3]:= NumericQ[result[[1]]]
Out[3]= True
In[4]:= NumberQ[result[[1]]]
Out[4]:= True
!!
Yet I haven't been able to find a pattern that matches NaN`
and not all other numbers (for use in Position
, Cases
, etc.).
So what are ways of a) passing NaN's from c into Mathematica so that Mathematica interprets them as Indeterminate
, or b) handling these NaN
s inside mathematica (with a pattern match to replace them with Indeterminate
, for example).
Is it possible to construct the first element of result
using keyboard input? Note that InputForm[result[[1]]]
gives NaN
, and NumericQ[InputForm[result[[1]]]]
gives False
.
NaN
have a backtick at the end? That's unusual, as normally only numbers would have that, not symbols. I am curious what isresult
'sFullForm
. $\endgroup$1.0`30
indicates1.0
to 30 digits of precision.1`
just indicated a machine precision number (same as1.0
). $\endgroup$