You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Charles Cooper (JIRA)" <ji...@apache.org> on 2013/03/25 20:09:16 UTC

[jira] [Commented] (MATH-954) Faster implementation of FastMath.abs

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

Charles Cooper commented on MATH-954:
-------------------------------------

You're right. When I did copySign I found that the branch was actually faster than bit twiddling so I assumed the call to Double.longBitsToDouble had high overhead. But in fact the bit twiddling is significantly faster in this case (by like 10 times, lol). Patch attached.

Cheers
Charles

                
> Faster implementation of FastMath.abs
> -------------------------------------
>
>                 Key: MATH-954
>                 URL: https://issues.apache.org/jira/browse/MATH-954
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.1.1
>         Environment: java version "1.6.0_27"
> OpenJDK Runtime Environment (IcedTea6 1.12.4) (6b27-1.12.4-1)
> OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
> Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.39-2 x86_64 GNU/Linux
> Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
>            Reporter: Charles Cooper
>            Priority: Minor
>              Labels: optimization, patch
>             Fix For: 3.2
>
>         Attachments: patch, patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> Faster implementations of abs() which use bitwise operations in preference to branching. By my benchmark abs(double/float) are about 10-20% faster, and abs(long/int) more than twice as fast. Patch attached.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira