<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — EXP function in dll crashing]]></title>
	<link rel="self" href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=338&amp;type=atom" />
	<updated>2014-04-25T13:36:02Z</updated>
	<generator>PunBB</generator>
	<id>http://forums.approximatrix.com/viewtopic.php?id=338</id>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1398#p1398" />
			<content type="html"><![CDATA[<p>I&#039;ve been experimenting with various configurations, and I can&#039;t personally get the wrong answer to occur when using a DLL.&nbsp; However, my test case may be overly simple.&nbsp; I do believe you are seeing an issue simply based on earlier reports of issues with quad-precision exponential calls.&nbsp; I&#039;m still looking into it further.</p><p>A new compiler version and accompanying runtime library will be coming soon that could fix the issue, but I wouldn&#039;t guarantee that it will.&nbsp; I&#039;ll keep investigating.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2014-04-25T13:36:02Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1398#p1398</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1397#p1397" />
			<content type="html"><![CDATA[<p>Jeff:</p><p>Any updates on the EXP function issue?</p><p>Thank you for your support.</p>]]></content>
			<author>
				<name><![CDATA[sankarnkp]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3473</uri>
			</author>
			<updated>2014-04-24T18:34:05Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1397#p1397</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1385#p1385" />
			<content type="html"><![CDATA[<p>Jeff:</p><p>Thank you for your assistance.</p><p>David:<br />The dll contains the following subroutine. This subroutine is then called from a different exe.</p><div class="codebox"><pre><code>SUBROUTINE TryDll(Var1,Var2,Var3,Var4)

  !DEC$ ATTRIBUTES DLLEXPORT :: TryDLL
  
  REAL, INTENT(IN) :: Var1
  REAL, INTENT(IN) :: Var2
  REAL             :: ReturnResult
  
  REAL, INTENT(OUT) :: Var3
  REAL, INTENT(OUT) :: Var4
  
  Var3 = Add(Var1,Var2)
  ReturnResult = Subtract(Var1,Var2)
  Var4 = EXP(ReturnResult)

END SUBROUTINE</code></pre></div><p>The above subroutine works well when called from the calling program as long as the argument to EXP is declared as REAL. But when I convert that to DOUBLE PRECISION, the subroutine crashes when called from outside exe.</p><p>I have the Options -&gt; Compiler -&gt; Use Double Precision for all REALS as checked. </p><p>Thank you for the help!!</p><p>Frank:</p><p>That routine looks interesting. Will try and let you know how it goes. Thanks</p><p>Regards<br />Sankar</p>]]></content>
			<author>
				<name><![CDATA[sankarnkp]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3473</uri>
			</author>
			<updated>2014-04-14T16:04:30Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1385#p1385</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1383#p1383" />
			<content type="html"><![CDATA[<p>SF Users,</p><p>Regarding the gfortran EXP() function, I&#039;ve had problems with some mathematical functions containing EXP()s.&nbsp; Although I&#039;m not sure if the problem is with the EXP() function or my regression algorithm, however I thought it was worth mentioning here.&nbsp; On some occasions I&#039;ve resorted to using the following algorithm in place of fortran&#039;s intrinsic EXP() function.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Function VEXP(x)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IMPLICIT REAL*8 (A-H,O-Z), INTEGER*4 (I-N)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REAL(dpr),INTENT(IN) :: x<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REAL(dpr) :: VEXP</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REAL(dpr) :: xx, E, F, G, H, B, C, D<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REAL(dpr) :: P, Q, R, A, AA, Y, Z, W<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTEGER(lpr) :: I, K, N</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PARAMETER ( F = 0.50D0, G = 1.0D0, H = 0.D0 )<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PARAMETER ( P = 0.50D0, Q = 0.333333333333D0, R = 0.25D0 )<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PARAMETER ( B = 690.D0, C = 1.D-34, D = 1.D+35 )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !--- Precision<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PARAMETER ( N = 9 )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ALLOCATABLE A(:), W(:)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; E = 2.7182818284590452353602874713527D0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx = x</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !--- real, parameter:: inf= 1./0., nan= 0./0., minf= -1./0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !--- NaN is never equal to anything<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ( xx .NE. xx ) xx = C</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !--- INFINITE(xx) = 1./0. IF xx IS INFINITE<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ! ERROR! &gt;&gt;&gt; IF ( (xx + G) .EQ. xx ) xx = B &lt;&lt;&lt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ! REPLACED &#039;G&#039; WITH &#039;HUGE&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ( (xx + HUGE(1.D308)) .EQ. xx ) xx = 690.D0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (DABS(xx) .LE. C) Then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VEXP = G<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RETURN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf (Abs(xx) .GE. B) Then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ( xx .LT. H ) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx = -B<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VEXP = C<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RETURN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx = +B<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VEXP = D<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RETURN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END IF<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ALLOCATE( A(N), W(N) )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !--- A(i) = DEXP(0.5**i)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(1) = 1.6487212707001281468486507878142D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(2) = 1.2840254166877414840734205680624D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(3) = 1.1331484530668263168290072278118D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(4) = 1.0644944589178594295633905946429D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(5) = 1.0317434074991026709387478152815D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(6) = 1.0157477085866857474585350720824D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(7) = 1.0078430972064479776934535597601D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(8) = 1.0039138893383475734436096039035D0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A(9) = 1.0019550335910028120465188980475D0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K = INT(xx)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx = xx - DBLE(K)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AA = F</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Z = xx<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DO I = 1, N<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; W(I) = H<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF ( Z .GT. AA ) W(I) = G<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Z = Z - W(I)*AA<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AA = F * AA<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END DO</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y = G<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DO I = 1, N<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF (W(I) .GT. H) Y = Y * A(I)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END DO</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y = Y*(G + Z*(G + P*Z * (G + Q*Z * (G + R*Z))))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF (K .LT. 0) E = G / E</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF (ABS(K) .GE. 1) THEN<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DO I = 1, ABS(K)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y = Y * E<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END DO<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx = xx + K<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END IF</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VEXP = Y</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DEALLOCATE( A, W )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Function VEXP</p><p>Some SF users may find this useful, although slow.</p><p>Frank</p>]]></content>
			<author>
				<name><![CDATA[drfrank]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=223</uri>
			</author>
			<updated>2014-04-12T22:24:20Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1383#p1383</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1382#p1382" />
			<content type="html"><![CDATA[<p>Actually, square roots of negative numbers are sometimes permitted. Can you post any of the code?</p>]]></content>
			<author>
				<name><![CDATA[davidb]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3463</uri>
			</author>
			<updated>2014-04-12T12:58:07Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1382#p1382</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1379#p1379" />
			<content type="html"><![CDATA[<p>Sankar,</p><p>I&#039;ll&nbsp; need to investigate this bug more fully.&nbsp; I&#039;m away on business for the weekend, but I&#039;ll be able to address your concerns this coming week.&nbsp; </p><p>Another user reported issues with EXP for REAL*16 values even when statically linked.&nbsp; It appears that the runtime library&#039;s EXP&nbsp; function is a bit of a problem.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2014-04-11T23:07:08Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1379#p1379</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[EXP function in dll crashing]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=1375#p1375" />
			<content type="html"><![CDATA[<p>I am stuck with a problem I am unable to solve:</p><p>- I have a exe which runs wonderfully. It uses a lot of intrinsic mathematical functions such as SQRT, ABS, EXP etc.<br />- Now I convert the exe to a dll. The dll compiles and links successfully. However, when I use the dll from another executable it would crash. My investigation lead me to the EXP calls. The point is that the call is a legal call with the right argument (the value being passed into EXP has a legitimate answer). When I comment out the EXP calls the program seems to work fine until it crashes due to unreasonable numbers resulting from not calculating EXP. Another thing I did was to add a SQRT just in front of the EXP call where the number passed into SQRT is not permitted (such as SQRT(-2)). IOn this situation the SQRT(-2) is calculated as NaN and program continues until it crashes at EXP.</p><p>I am really lost on why the EXP call works in EXE mode but not in DLL mode. While researching about this, I came to know that functions such as SQRT, ABS are calculated inline and functions like EXP requires run time libraries. Is this a reason? If so what run time libraries are needed. My gcc/gfortran is located in the path.</p><p>I am using Simply Fortran 1.45 (build 1256)</p><p>Any help will be greatly appreciated.</p><p>Regards<br />Sankar</p>]]></content>
			<author>
				<name><![CDATA[sankarnkp]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=3473</uri>
			</author>
			<updated>2014-04-11T20:14:12Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=1375#p1375</id>
		</entry>
</feed>
