D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3202 - std.math.pow cause dead loop
Summary: std.math.pow cause dead loop
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 critical
Assignee: Lars T. Kyllingstad
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-21 21:28 UTC by ZY Zhou
Modified: 2015-06-09 01:28 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ZY Zhou 2009-07-21 21:28:35 UTC
the case is:

   pow(1.01, int.min); 

because int.min == -int.min


Maybe the while loop should be put into pow(F, uint) instead of pow(F, int)
like the following:

pure nothrow F pow(F)(F x, int n)
{
   if (n < 0)
   {
      return 1 / pow(x, cast(uint)(-n));
   }
   return pow(x, cast(uint)n);
}
Comment 1 ZY Zhou 2009-07-21 22:54:26 UTC
(In reply to comment #0)
> Maybe the while loop should be put into pow(F, uint) instead of pow(F, int)
> like the following:

what about:

pure nothrow F pow(F)(F x, int n) if (isFloatingPoint!(F))
{
   if (n < 0)
      return 1 / pow(x, cast(uint)(-n));
   else
      return pow(x, cast(uint)n);
}

pure nothrow F pow(F)(F x, uint n) // allow integer if n is uint
{
  ...
}

This also solve #2973
Comment 2 Lars T. Kyllingstad 2010-06-22 00:14:42 UTC
http://www.dsource.org/projects/phobos/changeset/1677
Comment 3 Lars T. Kyllingstad 2010-08-11 02:43:44 UTC
Fixed DMD 2.048