You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2012/11/20 21:54:58 UTC
[jira] [Created] (MATH-905) FastMath.[cosh, sinh] do not support
the same range of values as the Math counterparts
Thomas Neidhart created MATH-905:
------------------------------------
Summary: FastMath.[cosh, sinh] do not support the same range of values as the Math counterparts
Key: MATH-905
URL: https://issues.apache.org/jira/browse/MATH-905
Project: Commons Math
Issue Type: Bug
Affects Versions: 3.0
Reporter: Thomas Neidhart
Fix For: 3.1
As reported by Jeff Hain:
cosh(double) and sinh(double):
Math.cosh(709.783) = 8.991046692770538E307
FastMath.cosh(709.783) = Infinity
Math.sinh(709.783) = 8.991046692770538E307
FastMath.sinh(709.783) = Infinity
===> This is due to using exp( x )/2 for values of |x|
above 20: the result sometimes should not overflow,
but exp( x ) does, so we end up with some infinity.
===> for values of |x| >= StrictMath.log(Double.MAX_VALUE),
exp will overflow, so you need to use that instead:
for x positive:
double t = exp(x*0.5);
return (0.5*t)*t;
for x negative:
double t = exp(-x*0.5);
return (-0.5*t)*t;
--
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
[jira] [Resolved] (MATH-905) FastMath.[cosh, sinh] do not support
the same range of values as the Math counterparts
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles resolved MATH-905.
-------------------------
Resolution: Fixed
Committed revision 1413600.
> FastMath.[cosh, sinh] do not support the same range of values as the Math counterparts
> --------------------------------------------------------------------------------------
>
> Key: MATH-905
> URL: https://issues.apache.org/jira/browse/MATH-905
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
> Attachments: MATH-905.diff
>
>
> As reported by Jeff Hain:
> cosh(double) and sinh(double):
> Math.cosh(709.783) = 8.991046692770538E307
> FastMath.cosh(709.783) = Infinity
> Math.sinh(709.783) = 8.991046692770538E307
> FastMath.sinh(709.783) = Infinity
> ===> This is due to using exp( x )/2 for values of |x|
> above 20: the result sometimes should not overflow,
> but exp( x ) does, so we end up with some infinity.
> ===> for values of |x| >= StrictMath.log(Double.MAX_VALUE),
> exp will overflow, so you need to use that instead:
> for x positive:
> double t = exp(x*0.5);
> return (0.5*t)*t;
> for x negative:
> double t = exp(-x*0.5);
> return (-0.5*t)*t;
--
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
[jira] [Updated] (MATH-905) FastMath.[cosh, sinh] do not support
the same range of values as the Math counterparts
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles updated MATH-905:
------------------------
Attachment: MATH-905.diff
Here is a patch for this issue.
The additional test methods "testMath905..." explore the range where the previous code would overflow (around [709, 710] and [-710, -709]).
Please note that the tolerance for those tests had to be increased to "3" (whereas it was "2" for the range [-30, 30]).
OK to commit?
> FastMath.[cosh, sinh] do not support the same range of values as the Math counterparts
> --------------------------------------------------------------------------------------
>
> Key: MATH-905
> URL: https://issues.apache.org/jira/browse/MATH-905
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
> Attachments: MATH-905.diff
>
>
> As reported by Jeff Hain:
> cosh(double) and sinh(double):
> Math.cosh(709.783) = 8.991046692770538E307
> FastMath.cosh(709.783) = Infinity
> Math.sinh(709.783) = 8.991046692770538E307
> FastMath.sinh(709.783) = Infinity
> ===> This is due to using exp( x )/2 for values of |x|
> above 20: the result sometimes should not overflow,
> but exp( x ) does, so we end up with some infinity.
> ===> for values of |x| >= StrictMath.log(Double.MAX_VALUE),
> exp will overflow, so you need to use that instead:
> for x positive:
> double t = exp(x*0.5);
> return (0.5*t)*t;
> for x negative:
> double t = exp(-x*0.5);
> return (-0.5*t)*t;
--
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
[jira] [Commented] (MATH-905) FastMath.[cosh, sinh] do not support
the same range of values as the Math counterparts
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13503578#comment-13503578 ]
Gilles commented on MATH-905:
-----------------------------
bq. Any specific reason why you prefer multiplication by 0.5 over division by 2, or just personal preference?
I've doing that since having read that multiplication is simpler (thus potentially faster) than division.
Never tried to benchmark.
> FastMath.[cosh, sinh] do not support the same range of values as the Math counterparts
> --------------------------------------------------------------------------------------
>
> Key: MATH-905
> URL: https://issues.apache.org/jira/browse/MATH-905
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
> Attachments: MATH-905.diff
>
>
> As reported by Jeff Hain:
> cosh(double) and sinh(double):
> Math.cosh(709.783) = 8.991046692770538E307
> FastMath.cosh(709.783) = Infinity
> Math.sinh(709.783) = 8.991046692770538E307
> FastMath.sinh(709.783) = Infinity
> ===> This is due to using exp( x )/2 for values of |x|
> above 20: the result sometimes should not overflow,
> but exp( x ) does, so we end up with some infinity.
> ===> for values of |x| >= StrictMath.log(Double.MAX_VALUE),
> exp will overflow, so you need to use that instead:
> for x positive:
> double t = exp(x*0.5);
> return (0.5*t)*t;
> for x negative:
> double t = exp(-x*0.5);
> return (-0.5*t)*t;
--
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
[jira] [Commented] (MATH-905) FastMath.[cosh, sinh] do not support
the same range of values as the Math counterparts
Posted by "Thomas Neidhart (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13503560#comment-13503560 ]
Thomas Neidhart commented on MATH-905:
--------------------------------------
Looks good to me.
Any specific reason why you prefer multiplication by 0.5 over division by 2, or just personal preference?
Searching in the FastMath source, there are several occurrences of both variants.
> FastMath.[cosh, sinh] do not support the same range of values as the Math counterparts
> --------------------------------------------------------------------------------------
>
> Key: MATH-905
> URL: https://issues.apache.org/jira/browse/MATH-905
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
> Attachments: MATH-905.diff
>
>
> As reported by Jeff Hain:
> cosh(double) and sinh(double):
> Math.cosh(709.783) = 8.991046692770538E307
> FastMath.cosh(709.783) = Infinity
> Math.sinh(709.783) = 8.991046692770538E307
> FastMath.sinh(709.783) = Infinity
> ===> This is due to using exp( x )/2 for values of |x|
> above 20: the result sometimes should not overflow,
> but exp( x ) does, so we end up with some infinity.
> ===> for values of |x| >= StrictMath.log(Double.MAX_VALUE),
> exp will overflow, so you need to use that instead:
> for x positive:
> double t = exp(x*0.5);
> return (0.5*t)*t;
> for x negative:
> double t = exp(-x*0.5);
> return (-0.5*t)*t;
--
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