<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=984</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=984&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Using I=TRANSFER (X,I) to detect Inf and NaN?.]]></description>
		<lastBuildDate>Wed, 25 Jun 2025 17:13:51 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4462#p4462</link>
			<description><![CDATA[<p>Jeff,</p><p>My error, you were correct that IEEE_IS_NAN and IEEE_IS_FINITE can be used successfully in SF with the expected Finite and NaN results of real numbers. I mistaken took the results of IEEE_IS_FINITE to mean INFINITE. Oops, sorry.</p><p>Frank</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Wed, 25 Jun 2025 17:13:51 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4462#p4462</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4460#p4460</link>
			<description><![CDATA[<p>Thanks Jeff,</p><p>I&#039;ve tried using USE IEEE_ARITHMETIC, ONLY: IEEE_IS_NAN, IEEE_IS_FINITE in SF, but could not achieved the expected NaN or +/- Inf results as was observed using my I=Transfer(x,I) approach.</p><p>Frank</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Wed, 25 Jun 2025 15:54:18 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4460#p4460</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4459#p4459</link>
			<description><![CDATA[<p>Frank,</p><p>Your scheme should work as long as the underlying system conforms to IEEE-754 mathematics.&nbsp; The Fortran standard does require IEEE-754 math, and I&#039;m not aware of any modern CPU architectures that aren&#039;t using it at this point.&nbsp; The last one to eschew that standard was maybe VAX.&nbsp; <em>EDIT: Some optimizations can cause the compiler and/or CPU to ignore the standard in favor of speed</em>.</p><p>You might instead want to look at the Fortran 2003 <strong>ieee_arithmetic</strong> module, which our compiler does support.&nbsp; The documentation is severely lacking, but the module does provide:</p><p>&nbsp; &nbsp; <strong>ieee_is_finite(x)</strong> – determine if a value is finite.<br />&nbsp; &nbsp; <strong>ieee_is_nan(x)</strong> – determine if a value is IEEE NaN</p><p>The module is part of the Fortran standard, so it might be a more reliable route.</p><p>There is some explanation at <a href="https://fortranwiki.org/fortran/show/ieee_arithmetic">the Fortran wiki</a>.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 25 Jun 2025 14:53:05 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4459#p4459</guid>
		</item>
		<item>
			<title><![CDATA[Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4456#p4456</link>
			<description><![CDATA[<p>Hi Jeff,</p><p>I have a question regarding the detection of numeric values that return Infinity (Inf) and Not-a-Number (NaN).<br />I&#039;ve observed that the TRANSFER() function can be used to detect +Inf, -Inf, and NaN occurrences when its value is compared to four different integer values. </p><p>For single-precision reals, these transfer function integers are,<br />I value = -8388608&nbsp; &nbsp; &nbsp; &nbsp;(represents -Infinity)<br />I value =&nbsp; 2139095040&nbsp; (represents +Infinity)<br />I value = -4194304&nbsp; &nbsp; &nbsp; &nbsp;(represents NaN)<br />I value = 2143289344&nbsp; &nbsp;(represents NaN)</p><p>And for double-precision reals, the transfer function integers are,<br />I value = -4503599627370496&nbsp; &nbsp; &nbsp; &nbsp;(represents -Infinity)<br />I value =&nbsp; 9218868437227405312&nbsp; (represents +Infinity)<br />I value = -2251799813685248&nbsp; &nbsp; &nbsp; &nbsp;(represents NaN)<br />I value =&nbsp; 9221120237041090560&nbsp; (represents NaN)</p><p>Using SF, I was able to easily detect the occurrences of -Inf, +Inf, and NaN in a program. I&#039;ve attached some code that provides a little more detail below.</p><p>My question is, simply, is this relationship of Transfer() functions of reals to integers representing Inf and NaN compiler specific? <br />In other words, would different compilers use different identifiable integers representing +Inf, -Inf, and NaN?</p><p>Although this relationship was new to me, perhaps it is more commonly known.</p><p>Regards,<br />Frank</p><p>!-----------------------------------------------------------------------<br />!<br />!&nbsp; Single-precision IsReal4.f90<br />!<br />&nbsp; &nbsp; INTEGER(KIND=4)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :: I&nbsp; &nbsp; &nbsp; !--- (KIND=4)</p><p>&nbsp; &nbsp; !--- rNEGINF equivalent I value = -8388608&nbsp; &nbsp; &nbsp;(-Infinity)<br />&nbsp; &nbsp; !--- rPOSINF equivalent I value =&nbsp; 2139095040&nbsp; (+Infinity)<br />&nbsp; &nbsp; !--- rNAN1&nbsp; &nbsp;equivalent I value = -4194304&nbsp; &nbsp; &nbsp;(NaN)<br />&nbsp; &nbsp; !--- rNAN2&nbsp; &nbsp;equivalent I value = 2143289344&nbsp; &nbsp;(NaN)<br />&nbsp; &nbsp; REAL(KIND=4), PARAMETER&nbsp; :: rNEGINF = 8388608.0<br />&nbsp; &nbsp; REAL(KIND=4), PARAMETER&nbsp; :: rPOSINF = 2139095040.0<br />&nbsp; &nbsp; REAL(KIND=4), PARAMETER&nbsp; :: rNAN1&nbsp; &nbsp;= 4194304.0<br />&nbsp; &nbsp; REAL(KIND=4), PARAMETER&nbsp; :: rNAN2&nbsp; &nbsp;= 2143289344</p><p>&nbsp; &nbsp; !--- TRANSFER REAL NUMBER TO INTEGER VALUE<br />&nbsp; &nbsp; I = TRANSFER ( X, I )<br />!-----------------------------------------------------------------------</p><p>!-----------------------------------------------------------------------<br />!<br />!&nbsp; Double-precision IsReal8.f90<br />!<br />&nbsp; &nbsp; INTEGER(KIND=8)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:: I&nbsp; &nbsp; &nbsp;!--- (KIND=8)</p><p>&nbsp; &nbsp; !--- rNEGINF equivalent I value = -4503599627370496&nbsp; &nbsp; &nbsp;(-Infinity)<br />&nbsp; &nbsp; !--- rPOSINF equivalent I value =&nbsp; 9218868437227405312&nbsp; (+Infinity)<br />&nbsp; &nbsp; !--- rNAN1&nbsp; &nbsp;equivalent I value = -2251799813685248&nbsp; &nbsp; &nbsp;(NaN)<br />&nbsp; &nbsp; !--- rNAN2&nbsp; &nbsp;equivalent I value =&nbsp; 9221120237041090560&nbsp; (NaN)<br />&nbsp; &nbsp; REAL(KIND=8), PARAMETER&nbsp; :: rNEGINF =&nbsp; 4503599627370496.0<br />&nbsp; &nbsp; REAL(KIND=8), PARAMETER&nbsp; :: rPOSINF =&nbsp; 9218868437227405312.0<br />&nbsp; &nbsp; REAL(KIND=8), PARAMETER&nbsp; :: rNAN1&nbsp; &nbsp;=&nbsp; 2251799813685248.0<br />&nbsp; &nbsp; REAL(KIND=8), PARAMETER&nbsp; :: rNAN2&nbsp; &nbsp;=&nbsp; 9221120237041090560.0</p><p>&nbsp; &nbsp; !--- TRANSFER REAL NUMBER TO INTEGER VALUE<br />&nbsp; &nbsp; I = TRANSFER ( X, I )<br />!-----------------------------------------------------------------------</p><p>!-----------------------------------------------------------------------&nbsp; &nbsp; <br />!<br />!&nbsp; &nbsp;Test for NaN, Inf, and real number<br />!<br />&nbsp; &nbsp; R = REAL( ABS(I) )</p><p>&nbsp; &nbsp; IF (ABS(R - rNEGINF) &lt; eps) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; !--- -Infinity<br />&nbsp; &nbsp; &nbsp; &nbsp; IFLAG = -1<br />&nbsp; &nbsp; ELSEIF (ABS(R - rPOSINF) &lt; eps) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; !--- +Infinity<br />&nbsp; &nbsp; &nbsp; &nbsp; IFLAG = +1<br />&nbsp; &nbsp; ELSEIF ((ABS(R - rNAN1) &lt; eps).OR.(ABS(R - rNAN2) &lt; eps)) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; !--- NaN<br />&nbsp; &nbsp; &nbsp; &nbsp; IFLAG = 2<br />&nbsp; &nbsp; ELSE<br />&nbsp; &nbsp; &nbsp; &nbsp; !--- Real number<br />&nbsp; &nbsp; &nbsp; &nbsp; IFLAG = 0<br />&nbsp; &nbsp; END IF<br />!-----------------------------------------------------------------------</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Tue, 24 Jun 2025 19:10:58 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4456#p4456</guid>
		</item>
	</channel>
</rss>
