Thoughts from Dan Miser RSS 2.0
 Thursday, September 14, 2006
As a follow up from my post yesterday, I have some work-arounds to get me past the problem. I still don't have the ultimate answer for why Math.Log(0.0) throws an exception only when called from COM interop, but I can at least move forward again.

I started out by changing the actual code in Lucene to simply avoid the Math.Log(0.0) statement. However, I started to worry about forking the code. I don't want that kind of maintenance headache as new versions of Lucene continue to come out. I was able to work things out so that I could descend a couple of classes, override some methods, and plug these into my API layer, and everything worked fine.

The one problem left was the arithmetic overflow that I got later on in the Lucene code. I was talking with Chris Bensen, and he recalled running into something similar before and sent this link to MSDN on _controlfp documentation. I implemented the following code in .NET in the constructor of my API layer, and the overflow error went away, but of course, I end up getting NaN results due to the new FPU masking behavior. I'll have to test thoroughly to make sure that this doesn't impact calculations further down the line.


    [DllImport("msvcrt.dll")] private static extern int _controlfp(int IN_New, int IN_Mask); // this imports the call 
    private const int _MCW_EM = 0x0008001f; 
    private const int _EM_INVALID = 0x00000010; 
    
    public LuceneAPI()
    {
      // Add this code to squelch arithmetic overflow/underflow exceptions spawned from the FPU.
      // See comments in the FixedDefaultSimilarity class for more information.
      _controlfp(_MCW_EM, _EM_INVALID);
    }

I still would like to find out the technical details for why I need to do any of this, but at least I have things running.

Thursday, September 14, 2006 9:58:00 AM (Central Standard Time, UTC-06:00)  #    Comments [2] -
.NET
Tracked by:
http://9nx-information.info/23003638/communication-mobile-phone-device.html [Pingback]
http://9ne-information.info/96661051/kitesurfing-salt-lake-city.html [Pingback]
http://9ny-information.info/53873195/index.html [Pingback]
http://9nu-information.info/93776897/index.html [Pingback]
http://9nu-information.info/29498542/index.html [Pingback]
http://9ni-information.info/53710438/epson-scanner-test.html [Pingback]
http://9nl-information.info/49918838/index.html [Pingback]
http://9nv-information.info/40655959/index.html [Pingback]
http://9nc-information.info/16772041/goo-goo-dolls-habitat-for-humanity-song.htm... [Pingback]
http://9nb-information.info/04868458/algolab-photo-vector-v1-98-61-software-revi... [Pingback]
http://9na-information.info/38684709/index.html [Pingback]
http://9or-information.info/01417751/index.html [Pingback]
http://9od-information.info/95862522/index.html [Pingback]
http://9ol-information.info/30637987/index.html [Pingback]
http://9on-information.info/66000387/index.html [Pingback]
http://9of-information.info/53240628/prices-oflite-on-18x-dvd-writer.html [Pingback]
http://9qh-information.info/96740196/index.html [Pingback]
http://9qt-information.info/80264843/parola-plurale.html [Pingback]
http://9op-information.info/98214775/index.html [Pingback]
http://9qh-information.info/32049356/index.html [Pingback]
http://9sg-information.info/33152572/tutto-leggi-relative-ai-contributo-inps.htm... [Pingback]
http://9rx-information.info/94141533/buy-a-retail-business.html [Pingback]
http://9sd-information.info/40349452/pensioni-isernia.html [Pingback]
http://9sf-information.info/84009971/index.html [Pingback]
http://9rn-information.info/00047395/toefl-ibt-test.html [Pingback]
http://9sa-information.info/49481355/costruire-pista-slot.html [Pingback]
http://9rg-information.info/36826450/index.html [Pingback]
http://9rp-information.info/61216168/aeriel-fitness-equipment-kmart.html [Pingback]
http://9sf-information.info/99508423/little-hentai.html [Pingback]
http://9uaff-le-informazioni.info/79372015/serafini-e-vidotto.html [Pingback]
http://9uafl-le-informazioni.info/59209638/index.html [Pingback]
http://9uaek-le-informazioni.info/77842754/index.html [Pingback]
http://9uaea-le-informazioni.info/45505675/index.html [Pingback]
http://9uaeo-le-informazioni.info/91943986/index.html [Pingback]
http://9uafr-le-informazioni.info/07528582/vb-esempio.html [Pingback]
http://9uafe-le-informazioni.info/78912676/playstation-il-padrino.html [Pingback]
http://9uafh-le-informazioni.info/66446015/foto-di-ragazze-del-est.html [Pingback]
http://9uafi-le-informazioni.info/95295709/index.html [Pingback]
http://9uaeo-le-informazioni.info/00872247/elisa-rivombrosa-2-it.html [Pingback]
http://9uaei-le-informazioni.info/38521661/volo-aereo-palermo-amsterdam.html [Pingback]
http://9uagi-le-informazioni.info/47411128/webbrowser1.html [Pingback]
http://9uagq-le-informazioni.info/48848509/index.html [Pingback]
http://9uagb-le-informazioni.info/43280234/index.html [Pingback]
http://9uagq-le-informazioni.info/90747319/index.html [Pingback]
http://9uahe-le-informazioni.info/17432835/amante-pompino-ingoio.html [Pingback]
http://9uagp-le-informazioni.info/35481115/password-dragon-ball-tenkaichi2.html [Pingback]
http://9uaho-le-informazioni.info/99055110/index.html [Pingback]
http://9uagt-le-informazioni.info/93497622/selen-adolescenza-perversa.html [Pingback]
http://9uaga-le-informazioni.info/86316868/click-audio.html [Pingback]
http://9uagq-le-informazioni.info/10973287/index.html [Pingback]
Friday, September 15, 2006 1:23:00 AM (Central Standard Time, UTC-06:00)
Hi Dan,



I'm pretty sure this happens because by default, Delphi runs with floating point exceptions enabled, while .NET code (and most MS generated code) assumes that floating point exceptions will not be raised, but denormals like NaN and +/-Inf will be generated and returned instead.



To avoid this, the simplest solution is probably to turn offf floating point exceptions in the Delphi Win32 app, like this:



Math.SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,

exOverflow, exUnderflow, exPrecision]);



Read more about it in Jon Shemitz' book ".NET for

Delphi programmers" or my post here:



http://groups.google.com/group/borland.public.delphi.language.basm/browse_frm/thread/4db602806044a282/4658a8ffd412ad43?lnk=st&q=vassbotn+finitefloat&rnum=2&hl=en#4658a8ffd412ad43

Friday, September 15, 2006 8:19:00 AM (Central Standard Time, UTC-06:00)
Thanks, Hallvard. I'll look into this a little more.
Comments are closed.
Navigation
Archive
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 308
This Year: 23
This Month: 1
This Week: 0
Comments: 604
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)