<div dir="ltr">Dear colleagues,<div><br></div><div>I recently discovered that normalize() function of scitbx::vec3&lt;double&gt; is not safe, i.e. this case </div><div>scitbx::vec3&lt;double&gt; a(0,0,0);</div><div>a.normalize();</div><div>it will produce division by zero and fail. If function contains this being called from python the traceback would be rather vague:</div><div>&lt;...&gt;</div><div><div>Floating-point error (Python and libc call stacks above)</div><div>                This crash may be due to a problem in any imported</div><div>                Python module, including modules which are not part</div><div>                of the cctbx project. To disable the traps leading</div><div>                to this message, define these environment variables</div><div>                (e.g. assign the value 1):</div><div>                    BOOST_ADAPTBX_FPE_DEFAULT</div><div>                    BOOST_ADAPTBX_SIGNALS_DEFAULT</div><div>                This will NOT solve the problem, just mask it, but</div><div>                may allow you to proceed in case it is not critical.</div></div><div><br></div><div>The code that generates this error sits in scitbx/vec3.h, lines 143-153 with a comment that this was done intentionally and a pointer to an appropriate function to do safe normalization. This function is not wrapped to be available in python directly. </div><div><br></div><div>Similar functionality (but coded in a different place) accessible via python by:</div><div><div>&gt;&gt;&gt; from scitbx import matrix</div><div>&gt;&gt;&gt; b = matrix.col([0,0,0])</div><div>&gt;&gt;&gt; b.normalize()</div><div>Traceback (most recent call last):</div><div>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;</div><div>  File &quot;/net/anaconda/raid1/olegs/phenix_queue/modules/cctbx_project/scitbx/matrix/__init__.py&quot;, line 270, in normalize</div><div>    return self / abs(self)</div><div>  File &quot;/net/anaconda/raid1/olegs/phenix_queue/modules/cctbx_project/scitbx/matrix/__init__.py&quot;, line 158, in __truediv__</div><div>    return rec([e/other for e in self.elems], self.n)</div><div>ZeroDivisionError: float division by zero</div></div><div><br></div><div>Fast grepping shows that normalize() is widely used in xfel, smtbx, rstbx, dxtbx, mmtbx/hydrogens, scitbx/rigid_body, and in some other places.</div><div><br></div><div>My questions to CCTBX community are:</div><div>1. Were you aware of this issue?</div><div>2. Should we do something about it: </div><div>  - make the function more safe and slow;</div><div>  - leave it like it is and let everybody know about the issue and let developers deal with it individually;</div><div>3. Any other input on the matter?</div><div><br></div><div>Best regards,</div><div>Oleg Sobolev. </div><div><br></div></div>