Difference between revisions of "Data Type Functions"

(added category)
 
(28 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
[[Category:Data Type Functions]]
 
[[Category:Data Type Functions]]
Analytica provides several functions for checking the data type of atoms (i.e., the items in an array).  These are found in the Special library.
+
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
  
= Function IsNaN =
+
__TOC__
  
IsNaN( X : Atomic )
+
Analytica provides several functions for checking the data type of atoms (i.e., the items in an array).  These are found in the [[Special_Functions_library|Special library]].
  
NaN is a special value arising from indeterminate arithmetic operations indicating "Not A Number".  NaN can arise from operations such as:
+
== Function IsHandle ==
0 / 0
 
0 * INF
 
INF - INF
 
IgnoreWarnings(Ln(-1))
 
IgnoreWarnings(Sqrt(-1))
 
  
The last two cases result in NaN since Analytica does not have internal support for complex numbers.  The other cases result because the result is indeterminate. 
+
:'''IsHandle'''(X : Atom)
 +
:'''IsHandle'''(X'', local: true'')
  
IsNaN(X) returns 1 (i.e., true) when X is the special value NaN, 0 (false) otherwise.
+
Tests whether the value in «X» is a [[handle]]. When «X» is array-valued, it tests whether each cell of the array contains a handle. The second form with <code>local: true</code> tests whether a local variable «X» contains a [[handle]].  For details, see [[IsHandle]].
  
= Function IsNumber =
+
== Function IsNaN ==
  
IsNumber( X : Atomic )  
+
:'''IsNaN'''(X: Atom)
  
Returns true when X is a number, or any of the special values INF, -INF, or NaN.
+
[[NaN]] is a special value arising from indeterminate arithmetic operations indicating "Not A Number".  [[NaN]] can arise from operations such as:
 +
:<code>0/0</code>
 +
:<code>0*INF</code>
 +
:<code>INF - INF</code>
 +
:<code>IgnoreWarnings(Ln(-1))</code>
 +
:<code>IgnoreWarnings(Sqrt(-1))</code>
  
 +
The last two cases result in [[NaN]] since Analytica does not have internal support for [[Complex Numbers|complex numbers]] (see [[Ln]], [[Sqrt]] and [[IgnoreWarnings]]).  The other cases result because the result is indeterminate. 
  
= Function IsReference =
+
'''IsNaN'''(X) returns 1 (i.e., True) when «X» is the special value [[NaN]], 0 (false) otherwise.
  
Returns 1 (true) when X is a reference, 0 otherwise.  When X is a reference, you can use the #X operator.
+
== Function IsNumber ==
  
= Function IsText =
+
:'''IsNumber'''(X: Atom)
  
IsText( X : Atomic )  
+
Returns True when «X» is a number, or any of the special values [[INF]], -[[INF]], or [[NaN]]. It is also true when «X» is a complex number or a date-time number, since a date-time number is encoded as the number of days elapsed since the time origin. It returns false (zero) for text, even if the characters in the text could be parsed as a number.
  
Returns 1 (true) when X is a textual string, 0 otherwise.
+
== Function IsRealNumber ==
  
= Comparison to Null =
+
:'''IsRealNumber'''(X: Atom)
  
The expressions X=Null or X<>Null can be used to test whether X is the special system constant Null. Null results from certain operations where the value is not found, such as A[I=X] when X is not an element of I (and warnings are ignored).
+
Returns True when «X» is a real number or the special values [[INF]] or -[[INF]]. It also returns true when «X» is a date-time number, since a date-time number is considered to be a numeric value -- the number of days elapsed since the date origin. It differs from [[IsNumber]] in that it returns false (zero) for a complex or imaginary number or for the special value [[NaN]].
  
Null can also be detected using IsUndef(X).
+
== Function IsDateTime ==
  
= Function IsUndef =
+
:'''IsDateTime'''(X: Atom)
  
IsUndef(X : Atomic )
+
Returns True when «X» is a date-time. A date-time is a special time of number in Analytica that encodes the number of days elapsed since the date origin, which is normally ''1-Jan-1904'', or ''30-Dec-1899'' if the "Use Excel Date Origin" preference is set. The fractional part of a date-time number represents a time. When printed, date-time numbers use the Date number format.
  
Returns True if X is either of the two special system constants Undefined or Null. Undefined is a special system constant indicating that an attribute does not yet have a value, and also used to indicate that a value is not yet computed (e.g., that the (mid) value or probValue attribute do not yet have a value), or that an optional parameter to a function was not specified.  Null is a value returned by function evaluations indicating that a requested value is out-of-range or does not exist.
+
'''IsDateTime'''(X) is false for numbers other than those recognized as date-time numbers. It is also false for text values, even if the text itself appears to be a date or time.
  
The special value Null was introduced into Analytica 3.0.  Prior to that, many functions returned Undefined when values did not exist, but were changed to return Null.  To handle backward compatibility where the IsUndef function was being used to test for these values, IsUndef returns true in both cases.
+
== Function IsReference ==
  
= Function IsNotSpecified =
+
:'''IsReference'''(X)
  
  IsNotSpecified( X : Atomic )
+
Returns 1 (True) when «X» is a reference, 0 otherwise. When «X» is a reference, you can use the [[#X operator]].
  
Used within a user-defined function to determine whether an optional parameter has a value.  If the optional parameter is not specified in the function call, and if the parameter has no default value, then IsNotSpecified returns true.
+
== Function IsText ==
  
For example:
+
:'''IsText'''(X: Atom)
  Function Fu1( A : Numeric ; B : optional numeric )
+
 
  Definition:  
+
Returns 1 (True) when «X» is a textual string, 0 otherwise.
        if IsNotSpecified(B) Then B := sqrt(A);
+
 
        Normal(A*Time,B*sqrt(T))
+
== Comparison to Null ==
 +
 
 +
The expressions <code>X = Null</code> or <code>X <> Null</code> can be used to test whether «X» is the special system constant [[Null]].  [[Null]] results from certain operations where the value is not found, such as <code>A[I = X]</code> when <code>X</code> is not an element of <code>I</code> (and warnings are ignored).
 +
 
 +
[[Null]] can also be detected using '''IsUndef'''(X).
 +
 
 +
== Function IsUndef ==
 +
 
 +
:'''IsUndef'''(X: Atom)
 +
 
 +
Returns True if «X» is either of the two special system constants [[Undefined]] or [[Null]].  [[Undefined]] is a special system constant indicating that an attribute does not yet have a value, and also used to indicate that a value is not yet computed (e.g., that the ([[Mid]]) value or [[probValue]] attribute do not yet have a value), or that an optional parameter to a function was not specified.  [[Null]] is a value returned by function evaluations indicating that a requested value is out-of-range or does not exist. 
 +
 
 +
The special value [[Null]] was introduced into Analytica 3.0.  Prior to that, many functions returned [[Undefined]] when values did not exist, but were changed to return [[Null]].  To handle backward compatibility where the '''IsUndef''' function was being used to test for these values, '''IsUndef''' returns True in both cases.
 +
 
 +
== Function IsList ==
 +
''New to [[Analytica 6.5]]''
 +
 
 +
:<code>Function IsList(x)</code>
 +
 
 +
<code>IsList(x)</code> returns true when «x» is a list. It is false when «x» is a scalar or a non-list array.
 +
 
 +
Note that when the result of a Definition is a list, the list is promoted to be a self-index, at which point the value is an array rather than a list. Also, even though an index is defined using a list, the index value has been promoted to be a self-index, so will no longer be labelled as a list. Hence, this function is really only of use with local values.
 +
 
 +
Note that '''IsList''' is different from the other '''''IsXXXX''''' functions (other than IsNull) in that it does not [[Array Abstraction|array abstract]]. Instead of applying to each cell, it applies to the entire value.
 +
 
 +
Examples:
 +
 
 +
* IsList( ['one','two']) --> True
 +
* IsList( Time ) --> False
 +
* Local x:='a'..'z' Do IsList(x) --> True
 +
* LocalIndex J:='a'..'z' Do IsList( J) --> False
 +
 
 +
== Function IsNull ==
 +
 
 +
:'''IsNull'''(X)
 +
 
 +
Returns True if «X» is exactly [[Null]].  Returns False when «X» is another than [[Null]].  Does not [[Array Abstraction|array abstract]], so if «X» is an array, even an array containing [[Null]] cells, it still returns atomic False.  If you want to compare the cells of an array individually to [[Null]], use <code>x = Null</code>.  If you want to test whether an attribute is set, use
 +
:'''IsNull'''(attrib Of obj)
 +
 
 +
which will return False (0) if the attribute happens to contain an array with [[Null]].
 +
 
 +
Note that '''IsNull''' is different from the other '''''IsXXXX''''' functions (other than IsList) in that it does not [[Array Abstraction|array abstract]]. Instead of applying to each cell, it applies to the entire value.
 +
 
 +
== Function IsNotSpecified ==
 +
:'''IsNotSpecified'''(X: Atom)
  
= Function TypeOf =
+
Used within a user-defined function to determine whether an optional parameter has a value.  If the optional parameter is not specified in the function call, and if the parameter has no default value, then '''IsNotSpecified''' returns true.
  
TypeOf( X : Atomic ; Shallow : optional boolean )
+
For example:
 +
:<code>Function Fu1(A: Numeric; B: optional numeric)</code>
 +
:<code>Definition:</code>
 +
::<code>if IsNotSpecified(B) Then B := sqrt(A);</code>
 +
::<code>Normal(A*Time, B*sqrt(T))</code>
  
(New to Analytica 4.0)
+
== Function TypeOf ==
  
Returns the name of the atomic data type of X as a textual string.  When TypeOf is applied to an array, the result is an array, where each cell contains the data type of the corresponding item in the original array.
+
:'''TypeOf'''(X: Atom; Shallow: optional boolean)
  
The common return values for TypeOf(X) are the following:
+
Returns the name of the atomic data type of «X» as a textual string.  When '''TypeOf''' is applied to an array, the result is an array, where each cell contains the data type of the corresponding item in the original array.  When «shallow» is true, a less detailed type description is given.  In many cases, '''TypeOf''' exposes details of the internal representation being used; hence, it is preferable to make use of the '''''IsXXX'''''() functions when possible.
* "Numeric"    - whenever IsNumber(X)
 
* "Textual"      - whenever IsText(X)
 
* "Null"      - whenever X = Null
 
* "Undefined" - whenever IsUndef(X) and X<>Null
 
* "Reference" - whenever IsReference(X)
 
  
The above cases are uneffected by the optional Shallow parameter.
+
{|class="wikitable"
 +
! When <code>X</code> is:
 +
! <code>TypeOf(X)</code> returns:
 +
! <code>TypeOf(X, shallow: true)</code> returns:
 +
|-
 +
| A real number stored internally in IEEE 754 double binary float format || "Number" || "Number"
 +
|-
 +
| An integer value stored internally as a 64-bit signed integer || "Integer" || "Number"
 +
|-
 +
| A real-value stored internally in a fixed-point real number format || "FixedPoint" || "Number"
 +
|-
 +
| A date/time numeric value || "DateTime" || "DateTime"
 +
|-
 +
| A complex (imaginary) number || "ComplexNumber" || "ComplexNumber"
 +
|-
 +
| A boolean, e.g., a result of a comparison or logical operator (new in [[Analytica 6.6]]) || "Boolean" || "Number"
 +
|-
 +
| A textual value || "Text" || "Text"
 +
|-
 +
| [[Null]] || "Null" || "Null"
 +
|-
 +
| A Linear optimization Program (returned by [[DefineOptimization]]) || "LP" || "Custom"
 +
|-
 +
| A Quadratic optimization Program with linear constraints (returned by [[DefineOptimization]]) || "QP" || "Custom"
 +
|-
 +
| A Quadratically Constrained optimization Program (returned by [[DefineOptimization]]) || "QCP" || "Custom"
 +
|-
 +
| A Non-Linear optimization Program (returned by [[DefineOptimization]]) || "NLP" || "Custom"
 +
|-
 +
| An ODBC Record Set object || "RecordSet" || "Custom"
 +
|-
 +
| A parsed expression where the outermost operation is an operator || "Expression" || "Expression"
 +
|-
 +
| A parsed expression where the outermost operation is a function call || "FunctionCall" || "FunctionCall"
 +
|-
 +
| An in-memory binary data term ("blob") || "BinaryData" || "BinaryData"
 +
|-
 +
| An image (e.g., from a Pict attribute) || "«Picture(PNG)»" || "Custom"
 +
|-
 +
| A [[Handle]] to an object with the class «className» || "''«className»''", one of:
 +
"Decision"<br>
 +
"Variable"<br>
 +
"Chance"<br>
 +
"Objective"<br>
 +
"Constraint"<br>
 +
"Constant"<br>
 +
"Index"<br>
 +
"Function"<br>
 +
"Determ"<br>
 +
"Module"<br>
 +
"Module"<br>
 +
"Library"<br>
 +
"Form"<br>
 +
"Linkmodule"<br>
 +
"Linklibrary"<br>
 +
"Text"<br>
 +
"Button"<br>
 +
"Picture"<br>
 +
"Formnode"<br>
 +
"Alias"<br>
 +
"Attribute"<br>
 +
"Command"<br>
 +
"Graphstyletemplate"<br>
 +
"Sysfunction"<br>
 +
"Keyword"<br>
 +
| "Object"
 +
|-
 +
| A [[Reference]] || "Reference" || "Reference"
 +
|-
 +
| The data from an input or output attribute || "ObjectSet" || "ObjectSet"
 +
|}
  
In Analytica Optimizer, optimization programs are defined by LpDefine, QpDefine or NlpDefine, and create an optimization object.  For these objects, the following values result when Shallow is not specified or is false:
+
The parameter to '''TypeOf''' is evaluated.  So, if you apply this to a function parameter or local variable, the type of the value is returned, even if the parameter is declared as an index or variable type.  For example:
* "«LP»"      - An object returned by LpDefine
+
:<code>Function F1(A: Variable) := TypeOf(A)</code>
* "«QP»"      - An object returned by QpDefine
 
* "«NLP»"    - An object returned by NlpDefine
 
When Shallow is specified and set to True, each of these cases return "Custom", indicating an internal object instance customized for a particular function library.
 
  
Analytica atoms can, in some cases, contain object handles (aka varTerms).  See [[Meta-Inference]]For example, a VarTerm can be obtained using GetVariableByName("ident").  When TypeOf(X) is applied to a varTerm, the following values result when Shallow is not specified or is False:
+
When you call <code>F1(Ch1)</code>, the type of each atom in the value of <code>Ch1</code> is returned -- not the class of <code>Ch1</code>If you wanted the class of the object, it would be easiest to use:
* "Decision"
+
:<code>Function F2(A: Variable) := class of A</code>
* "Variable"
 
* "Chance"
 
* "Objective"
 
* "Constant"
 
* "Index"
 
* "Function"
 
* "Determ"
 
* "Module"
 
* "Module"
 
* "Library"
 
* "Form"
 
* "Linkmodule"
 
* "Linklibrary"
 
* "Text"
 
* "Button"
 
* "Picture"
 
* "Formnode"
 
* "Alias"
 
* "Attribute"
 
* "Command"
 
* "Graphstyletemplate"
 
* "Sysfunction"
 
* "Keyword"
 
In these cases, if Shallow is set to true, then the value "Object" is returned in the above cases.
 
  
In addition, there are some cases in which atomic values could contain special internal system data types.  These are uncommon in normal modeling, but can occur, for example, by making use of "attrib of Obj".  For example, an expression is obtainable using: fixeddef of Va1, when Va1 is defined as A+B.  In these cases, the following values may result:
+
which would return "Chance" when call <code>F2(Ch1)</code>.
* "Expression"    - A parsed expression where the outermost operation is an operator.  E.g., in a fixeddef
 
* "FunctionCall"  - An expression where the outermost operation is a function call, e.g., in a fixeddef attribute
 
* "Keyword"
 
* "ObjectSet"    - e.g., in a input or output attribute
 
* "Data"          - e.g., in a Pict attribute
 
  
The parameter to TypeOf is evaluated.  So, if you apply this to a function parameter or local variable, the type of the value is returned, even if the parameter is declared as an index or variable type.  For example:
+
==See Also==
Function F1( A : Variable ) := TypeOf(A)
+
* [[IsHandle]]
When you call F1(Ch1), the type of each atom in the value of Ch1 is returned -- not the class of Ch1.  If you wanted the class of the object, it would be easiest to use:
+
* [[Undefined]]
Function F2( A : Variable ) := class of A
+
* [[Special Functions library]]
which would return "Chance" when call F2(Ch1).
+
* [[Datatype functions]]
 +
* [[Function_parameter_qualifiers#Data_type_qualifiers|Data types of function parameters]]
 +
* [[:Category: Data Type Functions]]
 +
* [[:Category:Domain Access Functions]]

Latest revision as of 17:00, 30 June 2025


Analytica provides several functions for checking the data type of atoms (i.e., the items in an array). These are found in the Special library.

Function IsHandle

IsHandle(X : Atom)
IsHandle(X, local: true)

Tests whether the value in «X» is a handle. When «X» is array-valued, it tests whether each cell of the array contains a handle. The second form with local: true tests whether a local variable «X» contains a handle. For details, see IsHandle.

Function IsNaN

IsNaN(X: Atom)

NaN is a special value arising from indeterminate arithmetic operations indicating "Not A Number". NaN can arise from operations such as:

0/0
0*INF
INF - INF
IgnoreWarnings(Ln(-1))
IgnoreWarnings(Sqrt(-1))

The last two cases result in NaN since Analytica does not have internal support for complex numbers (see Ln, Sqrt and IgnoreWarnings). The other cases result because the result is indeterminate.

IsNaN(X) returns 1 (i.e., True) when «X» is the special value NaN, 0 (false) otherwise.

Function IsNumber

IsNumber(X: Atom)

Returns True when «X» is a number, or any of the special values INF, -INF, or NaN. It is also true when «X» is a complex number or a date-time number, since a date-time number is encoded as the number of days elapsed since the time origin. It returns false (zero) for text, even if the characters in the text could be parsed as a number.

Function IsRealNumber

IsRealNumber(X: Atom)

Returns True when «X» is a real number or the special values INF or -INF. It also returns true when «X» is a date-time number, since a date-time number is considered to be a numeric value -- the number of days elapsed since the date origin. It differs from IsNumber in that it returns false (zero) for a complex or imaginary number or for the special value NaN.

Function IsDateTime

IsDateTime(X: Atom)

Returns True when «X» is a date-time. A date-time is a special time of number in Analytica that encodes the number of days elapsed since the date origin, which is normally 1-Jan-1904, or 30-Dec-1899 if the "Use Excel Date Origin" preference is set. The fractional part of a date-time number represents a time. When printed, date-time numbers use the Date number format.

IsDateTime(X) is false for numbers other than those recognized as date-time numbers. It is also false for text values, even if the text itself appears to be a date or time.

Function IsReference

IsReference(X)

Returns 1 (True) when «X» is a reference, 0 otherwise. When «X» is a reference, you can use the #X operator.

Function IsText

IsText(X: Atom)

Returns 1 (True) when «X» is a textual string, 0 otherwise.

Comparison to Null

The expressions X = Null or X <> Null can be used to test whether «X» is the special system constant Null. Null results from certain operations where the value is not found, such as A[I = X] when X is not an element of I (and warnings are ignored).

Null can also be detected using IsUndef(X).

Function IsUndef

IsUndef(X: Atom)

Returns True if «X» is either of the two special system constants Undefined or Null. Undefined is a special system constant indicating that an attribute does not yet have a value, and also used to indicate that a value is not yet computed (e.g., that the (Mid) value or probValue attribute do not yet have a value), or that an optional parameter to a function was not specified. Null is a value returned by function evaluations indicating that a requested value is out-of-range or does not exist.

The special value Null was introduced into Analytica 3.0. Prior to that, many functions returned Undefined when values did not exist, but were changed to return Null. To handle backward compatibility where the IsUndef function was being used to test for these values, IsUndef returns True in both cases.

Function IsList

New to Analytica 6.5

Function IsList(x)

IsList(x) returns true when «x» is a list. It is false when «x» is a scalar or a non-list array.

Note that when the result of a Definition is a list, the list is promoted to be a self-index, at which point the value is an array rather than a list. Also, even though an index is defined using a list, the index value has been promoted to be a self-index, so will no longer be labelled as a list. Hence, this function is really only of use with local values.

Note that IsList is different from the other IsXXXX functions (other than IsNull) in that it does not array abstract. Instead of applying to each cell, it applies to the entire value.

Examples:

  • IsList( ['one','two']) --> True
  • IsList( Time ) --> False
  • Local x:='a'..'z' Do IsList(x) --> True
  • LocalIndex J:='a'..'z' Do IsList( J) --> False

Function IsNull

IsNull(X)

Returns True if «X» is exactly Null. Returns False when «X» is another than Null. Does not array abstract, so if «X» is an array, even an array containing Null cells, it still returns atomic False. If you want to compare the cells of an array individually to Null, use x = Null. If you want to test whether an attribute is set, use

IsNull(attrib Of obj)

which will return False (0) if the attribute happens to contain an array with Null.

Note that IsNull is different from the other IsXXXX functions (other than IsList) in that it does not array abstract. Instead of applying to each cell, it applies to the entire value.

Function IsNotSpecified

IsNotSpecified(X: Atom)

Used within a user-defined function to determine whether an optional parameter has a value. If the optional parameter is not specified in the function call, and if the parameter has no default value, then IsNotSpecified returns true.

For example:

Function Fu1(A: Numeric; B: optional numeric)
Definition:
if IsNotSpecified(B) Then B := sqrt(A);
Normal(A*Time, B*sqrt(T))

Function TypeOf

TypeOf(X: Atom; Shallow: optional boolean)

Returns the name of the atomic data type of «X» as a textual string. When TypeOf is applied to an array, the result is an array, where each cell contains the data type of the corresponding item in the original array. When «shallow» is true, a less detailed type description is given. In many cases, TypeOf exposes details of the internal representation being used; hence, it is preferable to make use of the IsXXX() functions when possible.

When X is: TypeOf(X) returns: TypeOf(X, shallow: true) returns:
A real number stored internally in IEEE 754 double binary float format "Number" "Number"
An integer value stored internally as a 64-bit signed integer "Integer" "Number"
A real-value stored internally in a fixed-point real number format "FixedPoint" "Number"
A date/time numeric value "DateTime" "DateTime"
A complex (imaginary) number "ComplexNumber" "ComplexNumber"
A boolean, e.g., a result of a comparison or logical operator (new in Analytica 6.6) "Boolean" "Number"
A textual value "Text" "Text"
Null "Null" "Null"
A Linear optimization Program (returned by DefineOptimization) "LP" "Custom"
A Quadratic optimization Program with linear constraints (returned by DefineOptimization) "QP" "Custom"
A Quadratically Constrained optimization Program (returned by DefineOptimization) "QCP" "Custom"
A Non-Linear optimization Program (returned by DefineOptimization) "NLP" "Custom"
An ODBC Record Set object "RecordSet" "Custom"
A parsed expression where the outermost operation is an operator "Expression" "Expression"
A parsed expression where the outermost operation is a function call "FunctionCall" "FunctionCall"
An in-memory binary data term ("blob") "BinaryData" "BinaryData"
An image (e.g., from a Pict attribute) "«Picture(PNG)»" "Custom"
A Handle to an object with the class «className» "«className»", one of:

"Decision"
"Variable"
"Chance"
"Objective"
"Constraint"
"Constant"
"Index"
"Function"
"Determ"
"Module"
"Module"
"Library"
"Form"
"Linkmodule"
"Linklibrary"
"Text"
"Button"
"Picture"
"Formnode"
"Alias"
"Attribute"
"Command"
"Graphstyletemplate"
"Sysfunction"
"Keyword"

"Object"
A Reference "Reference" "Reference"
The data from an input or output attribute "ObjectSet" "ObjectSet"

The parameter to TypeOf is evaluated. So, if you apply this to a function parameter or local variable, the type of the value is returned, even if the parameter is declared as an index or variable type. For example:

Function F1(A: Variable) := TypeOf(A)

When you call F1(Ch1), the type of each atom in the value of Ch1 is returned -- not the class of Ch1. If you wanted the class of the object, it would be easiest to use:

Function F2(A: Variable) := class of A

which would return "Chance" when call F2(Ch1).

See Also

Comments


You are not allowed to post comments.