Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • Or to use the OP's function private static bool HasBase(int b, int n) { return Math.Log(b,n)%1 == 0; } Commented Apr 27, 2017 at 19:37
  • 1
    Oh really? Math.Log(243, 3) % 1 = 0.99999999999999911 for example Commented Apr 27, 2017 at 19:37
  • True, you do need to be careful of floating point rounding errors Commented Apr 27, 2017 at 19:39
  • 4
    or use an epsilon like you should be using for all double comparisons Commented Apr 27, 2017 at 19:43
  • 2
    If OPs title is accurate, this answer is correct (although it has some possible issues with floating point errors that may invalidate the answer). However, OPs title doesn't match the posted question text. The title suggests they want to find X given a, b and a^X == b. However, the text suggests they want to find X given a, b and X^a == b. Commented Apr 27, 2017 at 19:54