[ 
https://issues.apache.org/jira/browse/GEOMETRY-50?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17028420#comment-17028420
 ] 

Alex Herbert commented on GEOMETRY-50:
--------------------------------------

Checking each value for over/underflow is costly. Even if the branch 
practically never occurs and branch prediction can learn to ignore the 'safe' 
branches there is still a cost to having to ensure those branches are not 
needed. You could run this with a size of 10 and see if the SafeNorm relatively 
improves. At that data size the branch prediction will be much better.

Also note that SafeNorm is written for arrays of any length. It could be 
unrolled for length 2 and 3. That may be an interesting addition to the 
benchmark.

{{Math.hypot}} ensures accuracy below 1 ULP. It does this with careful 
computation of the {{x^2+y^2}} to minimise round-off. This may not be needed 
here. However my tests show that this computation is not the only factor in 
performance, the number of unpredictable branches in the code play a key role.

I am going to put some analysis results on {{Math.hypot}} under a ticket for 
numbers. I'll link to this issue for reference.

 

> Overflow in Vector norm and distance
> ------------------------------------
>
>                 Key: GEOMETRY-50
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-50
>             Project: Apache Commons Geometry
>          Issue Type: Bug
>            Reporter: Baljit Singh
>            Priority: Major
>
> In Euclidean Vector classes (Vector2D, Vector3D), norm() and distance() rely 
> on Math.sqrt(), which can overflow if the components of the vectors are 
> large. Instead, they should rely on SafeNorm.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to