The Lost Art of Logarithms
lostartoflogarithms.com
The Lost Art of Logarithms
1–10 of 204 posts
Re: The Lost Art of Logarithms
#2I wanted to make sure that I always have at least enough room for any size and I didn't want to manually compute, so I wrote this:
var actualSize = Double.valueOf(Math.pow(2, Math.ceil(Math.log(approxSize) / Math.log(2)))).intValue();
A bit much for a single line, but just using some basic log rules in order to the correct exponent. I learned all this in high school, but some of my coworkers thought I was using this amazing, arcane bit of math that had never been seen before. I guess they never use log outside of Big-O notation.Re: The Lost Art of Logarithms
#3Re: The Lost Art of Logarithms
#4Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.
Some people have suggested the "triangle of power".
Re: The Lost Art of Logarithms
#5Re: The Lost Art of Logarithms
#6Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.
Re: The Lost Art of Logarithms
#7Is this the same author who wrote Win32 API books?
Re: The Lost Art of Logarithms
#8Re: The Lost Art of Logarithms
#9I started using LMAX Disruptor for some projects. One quirk with Disruptor is that the queue size always has to be an exponent of two. I wanted to make sure that I always have at least enough room for any size and I didn't want to manually compute, so I wrote this: var actualSize = Double.valueOf(Math.pow(2, Math.ceil(Math.log(approxSize) / Math.log(2)))).intValue(); A bit much for a single line, but just using some…
var actualSize = Integer.highestOneBit(approxSize - 1)
purely to avoid involving the horrors that live beneath the humble pow() and log().(Integer.highestOneBit, also known as “isolate leftmost bit”, “most significant one”, or the like, essentially has to be a primitive to be efficient, unlike its counterpart for the lowest bit, x&-x. The actual CPU instruction is usually closer to Integer.numberOfLeadingZeros, but that’s just a bitshift away.)
Re: The Lost Art of Logarithms
#10Notation for writing log has always bugged me. Like I feel like it should be more like ^ which would be the log base 10 of 527. That's not it, but something. The current notation just doesn't feel quite right.
https://mathcenter.oxford.emory.edu/site/math108/logs/ Some people have suggested the "triangle of power".
It wasn't until seeing the triangle and having the relationships explained that I had any clue about logarithms, up until then logs had been some archaic number that meant nothing to me.
Because of the triangle of power, I now rock up to B and B+ Trees and calculate the number of disc accesses each will require in the worst case, depending on the number of values in each block (eg, log2(n), log50(n) and log100(n))