In this post, the user offers a more than satisfactory review, but he's also made a few mistakes. The user claims:

log(2.0) is 0.3 so dividing by that is equivalent to multiplying by 3.3. That seems a bit large

That statement is wrong, in C/C++ log(x) is the natural logarithm log_e (also known as ln). The result of ln(2.0) is 0.69, not 0.3. The user was under the false assumption that log(x) was log10(x). I'm willing to bet this is because he used the log function on his calculator, not ln and forgot that the defaults for a calculator are not the same as C/C++.

The asker's code is actually correct, although, it does do more processing than it really needs to. Let's try calculating it by hand:

## Given

size is 10

Log = ceil(log((double) size) / log(2.0)


is equivalent to

Log = ceil(2.302 / 0.693)


is equivalent to

Log = ceil(3.321)


## Thusly

Log == 4

_capacity is then set to 1 << 4 which means capacity is 16.


As you can see, the asker's code correctly calculates size * golden ratio. Now, if he wanted to optimise the code, and thusly making it faster, he could simply do the following:

/* Define in a header somewhere */
#define GOLDEN_RATIO 1.61803398875

_capacity = (double)size * GOLDEN_RATIO;


I wanted to simply edit the user's answer and tell the asker that his only problem is that he's unnecessarily recalculating the golden ratio each call instead of statically defining it. If someone could edit the answer to prevent misinforming people who stumbled across it, I'd greatly appreciate it.

• This is typically handled by commenting on the incorrect answer. If you believe the answer has incorrect information, I would downvote and leave a comment explaining why. Ohh. Oops. You couldn't downvote yet, but still. The principle remains. Such an edit would "violate the intent of the author." – RubberDuck Jun 13 '15 at 11:09
• @RubberDuck I wasn't able to comment on the answer nor was I able to post a meta question. I ended up posting a normal question and then someone gave me some points to be able to move the question here. I think the answer should be fixed as it can lead others in the wrong direction. I myself used his answer for reference on a few things and never once noticed that he was wrong. It wasn't until i did the math by hand that I noticed. – Brett Jun 13 '15 at 11:31
• I left a comment on the answer pointing back to this meta, but I've got to be honest, I tend to trust Loki. He's really very good. But everyone's human. Hopefully he shows up. – RubberDuck Jun 13 '15 at 11:34
• @RubberDuck Thank you for that! You can see here that log is actually log_e not log_10. Put ln(2) in your calculator, or on Google's calculator, you'll see that log_e(2) is not, infact, 0.3. Now, try entering log(2.0) in the calculator, the answer will be ~0.3. This operation, is log_10. As the aforementioned website states, log() is log_e not log_10. log10() is the log_10 function. – Brett Jun 13 '15 at 12:10

We can understand your keenness to correct this mistake, but this isn't the way to go about it. You have several options:

1. Participate normally in the site until you have enough reputation (50 points) to leave a comment. (This is your best bet: the mistake has been there since August 2014, so I doubt that many people will be harmed if you leave it uncorrected for a few more weeks.)

2. Write your own answer to the question, and append a note pointing out the mistake. (But it should be a real answer, not just a placeholder for your correction.)

3. Suggest an edit to the post, correcting the mistake. Wait for your suggestion to be reviewed. (But note that there's a good chance that such an edit will be rejected — third-party edits are supposed to be for correcting spelling or improving formatting, not for changing the substantive content.)

• I'd give you an up-vote, but I'm really opposed to your third option. Don't make such edits. Ever. – Mast Jun 13 '15 at 12:29
• @Mast there is a few cases when such edits are required. They don't happen on CR main though ... Sometimes such an efit may be appropriate for meta-posts when some official policy changed or to canonoccalize such posts – Vogel612 Jun 13 '15 at 15:58

It's valid, but it is in a relatively trivial part of the answer that was secondary to the main point.

My points hold:

• 4 is too big a number.
• The fact that he uses log() every time is bad idea.
• A constant is a good idea.

But I fixed the answer by removing that part, to stop further discussion.