<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=984&amp;type=atom" />
	<updated>2025-06-25T17:13:51Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=984</id>
		<entry>
			<title type="html"><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4462#p4462" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[drfrank]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=223</uri>
			</author>
			<updated>2025-06-25T17:13:51Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4462#p4462</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4460#p4460" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[drfrank]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=223</uri>
			</author>
			<updated>2025-06-25T15:54:18Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4460#p4460</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4459#p4459" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-06-25T14:53:05Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4459#p4459</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Using I=TRANSFER (X,I) to detect Inf and NaN?]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4456#p4456" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[drfrank]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=223</uri>
			</author>
			<updated>2025-06-24T19:10:58Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4456#p4456</id>
		</entry>
</feed>
