Share via


NaN Values

The term NaN, which stands for "not a number," means a symbolic entity that represents a value not otherwise available in floating-point format.

There are two kinds of NaNs.

  • Quiet
    Represent unknown or uninitialized values.
  • Signaling
    Represent symbolic values and values that are too big or too precise for the format. Signaling NaNs raise an invalid operation exception whenever an operation is attempted on them.

Code Example

The following example shows how to compare any value to a NaN value.

XML File (NaNValues.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="NaNValues.xsl" ?>
<items>
   <item>100</item>
   <item>ABC</item>
</items>

XSLT File (NaNValues.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="items">
 <xsl:for-each select="item">
  <xsl:call-template name="IsNaN"/>
 </xsl:for-each>
</xsl:template>

<xsl:template name="IsNaN">
 <!-- Parameter defined here -->
 <xsl:param name="var" select="."/>
 <xsl:value-of select="$var"/>
 <xsl:if test="string(number($var)) = 'NaN'"> is a string. </xsl:if>
 <xsl:if test="string(number($var)) != 'NaN'"> is a number. </xsl:if>
</xsl:template>
</xsl:stylesheet>

Output

This is the output:

100 is a number. ABC is a string.