[Matrix-SIG] Generating NaN and catching exceptions
Yoon, Hoon (CICG - NY Program Trading)
HYoon@exchange.ml.com
Fri, 11 Jun 1999 09:57:24 -0400
Hi,
I was wondering how can I generate and use Python NaN's from my CXX code.
Currently I am using the code below: (which generates this 1.#QNAN thing in
NT)
I would like to change it to what I generate for Python by
INF = 1e1000**1000000
NA = (INF/INF)
I try passing in this to Cxx extension as arg, but that does not quite
work. Not to mention that I would like to assign this a variable rather than
function call. pyRTL.NA & not NA = pyRTL.mkMsg()
I guess I am really looking for what's equivalent to what's in #define
ISMISSING and MKMISSING.
One other thing is I tried, catch(const Exception&) { // Catch
ValueError?
but what I really want is catch(const ValueError&) whenever I pass in
something like a String, as arg to ex_tst_msg(), but it does not seem to
catch it. I thought that was strange, but C++ is a tempermental mistress.
Any sample code or help will be appreciated greatly!
hn_rtl.h file---------
//Unix Missing Values
//#define ISMISSINGVAL(A) ( (*((unsigned short *)(A)) & (unsigned
short)0x7FFF) > (unsigned short)0x7FF0 )
//#define MKMISSINGVAL(A) ( *((unsigned int *)(A)) = 0x7fffffff,
*((unsigned int *)(A)+1) = (unsigned int)0 )
// NT missing
#define ISMISSINGVAL(A) ( (*((unsigned short *)(A)+3) & (unsigned
short)0x7FFF) > (unsigned short)0x7FF0 )
#define MKMISSINGVAL(A) ( *((unsigned int *)(A)+1) = 0x7fffffff,
*((unsigned int *)(A)) = (unsigned int)0 )
in my cxx prg-----------------
static Float
mkMsg() {
double *msgV;
double msgv;
msgv = 0.0;
msgV = &msgv;
MKMISSINGVAL(msgV);
return Float(msgv);
}
static PyObject *
ex_mkMsg(PyObject* self, PyObject* args) {
return new_reference_to(mkMsg());
}
static PyObject *
ex_tst_msg(PyObject* self, PyObject* args) {
try {
Tuple tArgs(args);
Float isMsgV = Float(tArgs[0]);
double msgv = (double) isMsgV;
double *msgV = &msgv;
if ISMISSINGVAL(msgV) return new_reference_to(Int(1));
else return new_reference_to(Int(0));
// if (NAval == isMsgV) return new_reference_to(Int(0));
}
catch(const Exception&) { // Catch ValueError?
return new_reference_to(Int(0));
//cout << "Exception in clearing all ref.\n";
//return Null ();
}
}
**************************************************************
S. Hoon Yoon (Quant) Merrill Lynch
Equity Trading
yelled@yahoo.com hoon@bigfoot.com(w)
"Miracle is always only few standard deviations away, but so is
catastrophe."
* Expressed opinions are often my own, but NOT my employer's.
"I feel like a fugitive from the law of averages." Mauldin
**************************************************************