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:52:58 UTC
[jira] [Created] (MATH-904) FastMath.pow deviates from Math.pow for
negative, finite base values with an exponent 2^52 < y < 2^53
Thomas Neidhart created MATH-904:
------------------------------------
Summary: FastMath.pow deviates from Math.pow for negative, finite base values with an exponent 2^52 < y < 2^53
Key: MATH-904
URL: https://issues.apache.org/jira/browse/MATH-904
Project: Commons Math
Issue Type: Bug
Affects Versions: 3.0
Reporter: Thomas Neidhart
Fix For: 3.1
As reported by Jeff Hain:
pow(double,double):
Math.pow(-1.0,5.000000000000001E15) = -1.0
FastMath.pow(-1.0,5.000000000000001E15) = 1.0
===> This is due to considering that power is an even
integer if it is >= 2^52, while you need to test
that it is >= 2^53 for it.
===> replace
"if (y >= TWO_POWER_52 || y <= -TWO_POWER_52)"
with
"if (y >= 2*TWO_POWER_52 || y <= -2*TWO_POWER_52)"
and that solves it.
--
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-904) FastMath.pow deviates from Math.pow
for negative, finite base values with an exponent 2^52 < y < 2^53
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles resolved MATH-904.
-------------------------
Resolution: Fixed
Fixed in revision 1413916.
> FastMath.pow deviates from Math.pow for negative, finite base values with an exponent 2^52 < y < 2^53
> ------------------------------------------------------------------------------------------------------
>
> Key: MATH-904
> URL: https://issues.apache.org/jira/browse/MATH-904
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
>
> As reported by Jeff Hain:
> pow(double,double):
> Math.pow(-1.0,5.000000000000001E15) = -1.0
> FastMath.pow(-1.0,5.000000000000001E15) = 1.0
> ===> This is due to considering that power is an even
> integer if it is >= 2^52, while you need to test
> that it is >= 2^53 for it.
> ===> replace
> "if (y >= TWO_POWER_52 || y <= -TWO_POWER_52)"
> with
> "if (y >= 2*TWO_POWER_52 || y <= -2*TWO_POWER_52)"
> and that solves it.
--
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-904) FastMath.pow deviates from Math.pow
for negative, finite base values with an exponent 2^52 < y < 2^53
Posted by "Thomas Neidhart (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502679#comment-13502679 ]
Thomas Neidhart commented on MATH-904:
--------------------------------------
ah ok, thanks a lot, I found also an explanation here [http://en.wikipedia.org/wiki/Double-precision_floating-point_format]
> FastMath.pow deviates from Math.pow for negative, finite base values with an exponent 2^52 < y < 2^53
> ------------------------------------------------------------------------------------------------------
>
> Key: MATH-904
> URL: https://issues.apache.org/jira/browse/MATH-904
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
>
> As reported by Jeff Hain:
> pow(double,double):
> Math.pow(-1.0,5.000000000000001E15) = -1.0
> FastMath.pow(-1.0,5.000000000000001E15) = 1.0
> ===> This is due to considering that power is an even
> integer if it is >= 2^52, while you need to test
> that it is >= 2^53 for it.
> ===> replace
> "if (y >= TWO_POWER_52 || y <= -TWO_POWER_52)"
> with
> "if (y >= 2*TWO_POWER_52 || y <= -2*TWO_POWER_52)"
> and that solves it.
--
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-904) FastMath.pow deviates from Math.pow
for negative, finite base values with an exponent 2^52 < y < 2^53
Posted by "Thomas Neidhart (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502188#comment-13502188 ]
Thomas Neidhart commented on MATH-904:
--------------------------------------
Does anyone know the reason why numbers > 2^53 are assumed to be even?
Looking at the javadoc of Math.pow, this is not mentioned, only the general case:
{noformat}
If the first argument is finite and less than zero
if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
if the second argument is finite and not an integer, then the result is NaN.
{noformat}
> FastMath.pow deviates from Math.pow for negative, finite base values with an exponent 2^52 < y < 2^53
> ------------------------------------------------------------------------------------------------------
>
> Key: MATH-904
> URL: https://issues.apache.org/jira/browse/MATH-904
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
>
> As reported by Jeff Hain:
> pow(double,double):
> Math.pow(-1.0,5.000000000000001E15) = -1.0
> FastMath.pow(-1.0,5.000000000000001E15) = 1.0
> ===> This is due to considering that power is an even
> integer if it is >= 2^52, while you need to test
> that it is >= 2^53 for it.
> ===> replace
> "if (y >= TWO_POWER_52 || y <= -TWO_POWER_52)"
> with
> "if (y >= 2*TWO_POWER_52 || y <= -2*TWO_POWER_52)"
> and that solves it.
--
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-904) FastMath.pow deviates from Math.pow
for negative, finite base values with an exponent 2^52 < y < 2^53
Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502339#comment-13502339 ]
Luc Maisonobe commented on MATH-904:
------------------------------------
bq. Does anyone know the reason why numbers > 2^53 are assumed to be even?
Because the mantissa of a double number encoding using IEEE-754 cannot handle a sufficient number of digits. If the Most Significant Bit is large enough, the Least Significant Bit becomes equal to 2.0 (and later when you still increase the MSB, then the LSB will become 4.0, and after that 8.0...
This is the essence of "floating" in floating point numbers. The decimal separator "floats", up to the end of the number than it slips out of the number.
> FastMath.pow deviates from Math.pow for negative, finite base values with an exponent 2^52 < y < 2^53
> ------------------------------------------------------------------------------------------------------
>
> Key: MATH-904
> URL: https://issues.apache.org/jira/browse/MATH-904
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.0
> Reporter: Thomas Neidhart
> Fix For: 3.1
>
>
> As reported by Jeff Hain:
> pow(double,double):
> Math.pow(-1.0,5.000000000000001E15) = -1.0
> FastMath.pow(-1.0,5.000000000000001E15) = 1.0
> ===> This is due to considering that power is an even
> integer if it is >= 2^52, while you need to test
> that it is >= 2^53 for it.
> ===> replace
> "if (y >= TWO_POWER_52 || y <= -TWO_POWER_52)"
> with
> "if (y >= 2*TWO_POWER_52 || y <= -2*TWO_POWER_52)"
> and that solves it.
--
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