Serving the Quantitative Finance Community

 
User avatar
audetto
Topic Author
Posts: 0
Joined: March 12th, 2002, 4:08 pm

Math problem in MSVC

October 28th, 2002, 3:28 pm

Hi, I'm having some problems with math in MSVCI'm writing an XLL for ExcelI want to catch exceptions raised when I compute an invalid math function, like log(-1), sqrt(-1)but these instructions are perfectly legal and the result is -1.#IND00000 (I think it's NaN).there is a function "_matherr" which is called whenever there's a problem with math function (where you could raise your exceptions), but I can read on MSDN that this function can be overridden only in an application (EXE file) and not in a DLLdoes anybody have a good idea?byea
 
User avatar
lodette
Posts: 0
Joined: July 14th, 2002, 3:00 am

Math problem in MSVC

October 28th, 2002, 5:07 pm

Does the NaN propagate up to the caller? You could probably catch it there with an explicit test, the theory being that the exceptions mechanism should not be used in place of a test anyway.- Lou
 
User avatar
audetto
Topic Author
Posts: 0
Joined: March 12th, 2002, 4:08 pm

Math problem in MSVC

October 29th, 2002, 9:31 am

there's no propagation of NaN: it is a perfectly legal double number. all operations involving it producues an other NaN, but there is no exception anywhere... I can imagine only to write some wrappers where I raise an exception whenever the argument if out of the domain of the function, but I dislike it...
 
User avatar
rector
Posts: 0
Joined: July 14th, 2002, 3:00 am

Math problem in MSVC

October 29th, 2002, 12:07 pm

audetto,I believe lodette's idea was to check whether the result is correct only once at the top level. As all operations involving NaN produce NaN, the result of calculationg any expression with NaN is nan. And you need to check for NaN only when you finished the calculations. And taking into account that you can check the result once it is obtained, it seems to me even more convenient than hendling exceptions.Regards,Rector