PureBytes Links
Trading Reference Links
|
LJ,
I'm glad you have posted your question to the list, as I have tried to
respond to your original question many times. The response always bounces
back with an undeliverable address. At any rate, here is your original
question and the response:
-----Original Message-----
From: MS Developers Kit
Sent: Thursday, August 17, 2000 9:29 AM
To: 'laurent.jacob@xxxxxxxxxxxxxx'
Subject: FW: Exponential C fonction in MSX DLL
Hello,
You have not specified, but I assume you are using Microsoft Visual C++. By
default, VC++ ignores most floating point exceptions. Before calling an MSX
DLL, MetaStock (or MSXTest) enables the trapping of floating point
exceptions in an attempt to minimize incorrect results.
The exp() (which takes a double precision argument) produces an underflow
condition when its argument is less than -708, and an overflow condition
when its argument is greater than 709. When assigning the result of exp()
to a single precision float, the effective argument range for exp drops to
-87 to 88. VC++'s normal state is to ignore the underflow and produce a
result of zero, or ignore the overflow and produce a result of infinity.
You should calculate the argument that you are going to pass to exp, then
check it for a valid range. Something like this should work:
// calculate the argument for exp
double lfTemp = -1 * RateInt * LifeTime;
// perform the first part of the price calculation
price = SpotPrice * tmp1;
// if lfTemp is within valid range, perform rest of price calculation
// otherwise, the result would be zero anyway so ignore the additional
calculation.
if (lfTemp >= -87 && lfTemp <= 88)
price = ForceFloatRange(price - (StrikePrice * exp(lfTemp) * tmp2));
Note: DO NOT suppress the detection of floating point errors in your MSX
DLL. Instead, insert logic (like the above example) to handle potential
errors.
Good luck with your programming project.
Regards,
MSDevKit Support
-----Original Message-----
From: ljb [mailto:laurent.jacob@xxxxxxxxxxxxxx]
Sent: Sunday, September 03, 2000 7:29 AM
To: metastock@xxxxxxxxxxxxx
Subject: MSDK and exp() C function
hello,
I use the MSDK to build new functions. I have a function in a DLL which
uses the exponential function of C "exp() ". When I stress test this
function, I obtain a overflow even if I place in front of a
"ForceFloatRange" like this:
ForceFloatRange ( exp(mydata) );
Does somebody have a solution to avoid the overflow ?
Thank you for your answer
LJ
|