<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hi All,<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>My problem is that I’ve noticed a strange behavior in
Python while handling FPEs on Windows after switching compilers (msvc8 to
msvc9) and I am trying to find out how Python handles INF values to figure out
where the problem might be. <o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>The problem appeared when we noticed that behavior of
Numeric (older version of NumPy) library has changed when dealing with
Floating-Point Exceptions. We are building our own slightly modified version of
Python in-house (including Numeric/NumPy) and when we switched from the msvc8
to msvc9 compiler, Numeric started to return ‘-inf’ as a result of
‘Numeric.log10(0.0)’ instead of rasing an OverflowError. I know
that Numeric is using umath instead of the math library and since
math.log10(0.0) is still raising an Error (which is ValueError in 2.6 and
OverflowError in 2.4, but still an error) I thought that it might have
something to do with how umath or Numeric handles the input or return values of
log functions.<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Before hunting blindly I wanted to see how Python interprets
INF results. I built a simple module with only one function that causes an FPE
with log10(0.0) using C’s math library and prints the results with
printf. Then I imported that module from python, called the function and
printed the result in python too to see if there are any differences between
two values (which I found out that there are)<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Here is the that part of the code from my C Python module:<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>static
PyObject *badNum(PyObject *self, PyObject *args)</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>{</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
int sts = 0; //Not used, just dummy</span><o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
double a = 0.0;</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
double c = 0.0;</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
if (!PyArg_ParseTuple(args, "i", &sts)) //Dummy check, no use</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>       
return NULL;</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>  
 disableFPEs();</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
c = log10(a); //Since FPEs disabled, should return ‘-1.#INF’</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
enableFPEs();</span><o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
printf("C-Val: %f\n", c);</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>   
return Py_BuildValue("d", c);</span><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Lucida Console"'>}</span><o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>After I build the module and imported it into Python, I
called the function and printed the return value in Python. The output was
different in two versions of Python:<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Output1 (Module was built with msvc8 and run by python24)<o:p></o:p></p>

<p class=MsoNormal>C-Val: -1.#INF<o:p></o:p></p>

<p class=MsoNormal>Py-Val: -1.#INF<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Output2 (Module was built with msvc9 and run by python26)<o:p></o:p></p>

<p class=MsoNormal>C-Val: -1.#INF<o:p></o:p></p>

<p class=MsoNormal>Py-Val: -inf<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>I now know that compiler change didn’t cause any
change in return value of log10(0.0) at C level (both compilations resulted in
‘-1.#INF’) so I am thinking that somehow at somewhere in Python
core the value is translated into ‘-inf’ and that might be the
reason why Numeric/NumPy is missing the problem and having issues raising
OverflowError like it’s supposed to.<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>I started debugging Python.exe (with my module loaded) in
Visual Studio. While tracing what’s happening after the line “<span
style='font-size:10.0pt;font-family:"Lucida Console"'>return
Py_BuildValue("d", c);”</span> I went down to the
“floatobject.c “ file (which I thought is highly relevant to floating-point
value conversions) and in particular “format_float()” function but
since I am not that familiar with Python internals, I am having trouble
pinpointing the issue and the code where the “conversion” is
happening and I can’t even be sure if I am looking at the right place.<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>I would appreciate if someone could help me out or at least
could point me to the right direction so that I can figure out the rest.<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Thanks,<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>Best Regards,<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Ali
Erman CELEN</span><o:p></o:p></p>

<p class=MsoNormal><i><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Platform
Specialists / Porting</span></i><o:p></o:p></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Dassault
Systèmes I <a href="http://www.3ds.com/"><span style='color:windowtext;
text-decoration:none'>www.3ds.com</span></a></span><o:p></o:p></p>

</div>

<P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">If you are not one of the named recipients or have received this email in error, </P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(i) you should not read, disclose, or copy it,</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(ii) please notify sender of your receipt by reply email and delete this email and all attachments,</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email.</P><P style="FONT-STYLE: italic; MARGIN: 0px 0px 0px 35.4pt; FONT-FAMILY: Arial, Helvetica, sans-serif; COLOR: #1f497d; FONT-SIZE: 9pt"><P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">For other languages, <A href="http://www.3ds.com/terms/email-disclaimer">Click Here</A></P></body>

</html>