Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:06:40+00:00 2026-06-02T08:06:40+00:00

The following code is supposed to check to see if an inputed number is

  • 0

The following code is supposed to check to see if an inputed number is a power of 26. On the localhost the comparison evaluates as false when it should be true, but when it is running on the live php server it works as expected.

#there is an html text input
$foo = $_POST['someval'];

if(intval(log($foo, 26)) == floatval(log($foo, 26))) {
   echo 'yup, that there number is a power of 26';
}
else {
   echo 'nope, definitely not a power of 26';
}

I should note, on the localhost the “if” will SOMETIMES evaluate true. It happens for every other power of 26 (eg. 26 will be true, 676 (26 squared) will be false, 17576 (26 cubed) will be true). However when it is running on the live server, everything works as expected and the “if” evaluates true for every power of 26.

I can not figure out what is causing this discrepancy.
The live server is running PHP 5.3.8
I have tried two different local stacks (mamp & ampps) which are running PHP 5.3.6 & 5.3.10 respectively and the same thing occurs on both.

I have also tried writing the code so that the math is done outside of the “if” statement with no luck there either.

This is not a high priority issue since the code works where it is supposed to (live) but it is bugging me that there is a discrepancy. Let me know if you see what is going on or if you have a better way to check if a number is a power of 26.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:06:41+00:00Added an answer on June 2, 2026 at 8:06 am

    Because of floating-point roundoff issues, and the lack of promise of exactness (log($foo, 26) is probably computed internally as log($foo)/log(26), which involves a floating point division) this doesn’t sound like the kind of thing that you should count on working at all, let alone across different systems. I would suggest this instead:

    $foo == pow(26, (int)round(log($foo, 26)))
    

    which should always be exact as long as $foo fits within the PHP integer type to begin with. PHP’s pow promises that the result will be an integer if both arguments are integer and if the result is within range of an integer. By finding the base-26 log of $foo, rounding it, and raising 26 to that power, this code basically finds the nearest power of 26 to $foo, and then that power can be compared directly to $foo to see if they’re equal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a SMS app the following code is supposed to: check if
i've the following code, it's supposed to check if a variable from a DataList
I am adding the following code to check whether a checkbox should be checked
The following code is supposed to make the right 60% of the display red.
Given the following code (it's supposed to write helloworld in a helloworld file, and
I have the following code, which is supposed to try to parse a given
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Suppose I have the following code function myFunction(param, callback) { ... if (err) {
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.