commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Hain (JIRA)" <>
Subject [jira] [Commented] (MATH-901) FastMath.sin is slow
Date Tue, 20 Nov 2012 23:28:59 GMT


Jeff Hain commented on MATH-901:

>What would be an acceptable loss of accuracy, opinions?

If the user doesn't need correct rounding and monotonicity
subtleties, I think an acceptable loss should be about
1e-15, i.e. about the precision of doubles, so that there
is not much visible loss for a few lucky computations.
In jodk, tan/exp/pow accuracy can be as bad as about 1e-12,
but that's for relatively large values, and that's fine
since the user is (or should be!) aware that he's using
something designed to be fast more than accurate.

>If we decide to do something like this, we should also
>add a specific page in the user guide, describing the
>differences with figures for performance and accuracy.
>Right now, FastMath is advertised as safe drop-in replacement
>to Math, but with two diverting implementations with different
>goals, users would need more guidance I guess.

For a drop-in replacement to be really safe, it needs to
behave exactly (except for speed) like the original, but
current FastMath claims to be more accurate so it can't be

The JDK already has two Math classes (Math and StrictMath).
If you do a faster and safe drop-in replacement for one of these,
ideally you should try to get it into JDK since it's now open,
to avoid people ending up with too many implementations around
(I don't think it's worth it to have yet another class, just to
end up with similar accuracy and speed, especially for such low-level
Some people at Sun/Oracle already thought about faster and
pure java implementations, see mails at


> FastMath.sin is slow
> --------------------
>                 Key: MATH-901
>                 URL:
>             Project: Commons Math
>          Issue Type: Sub-task
>    Affects Versions: 3.0
>         Environment: Mac OS 10.8.2, Java 7
>            Reporter: Konstantin Berlin
>         Attachments:
> The FastMath.sin (maybe other functions too) are not nearly as fast as some other libraries
that can be found on the internet.
> The *much* faster code can be found here
> Max Absolute Error Apache vs JDK: 1.1102230246251565E-16
> Max Absolute Error Alternative vs JDK: 5.551115123125783E-16
> JDK Time: 0.698
> Apache Time: 0.491
> Alternative Time: 0.18
> I will add my test code as soon as I figure out how.

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:

View raw message