sunsetquest / fast-integer-log2 Goto Github PK
View Code? Open in Web Editor NEWBenchmark several others and also some of my own.
Benchmark several others and also some of my own.
I was surprised to see SunsetQuest3 reported as "no errors" in the output, when it looked suspicious (floats only have a 24-bit mantissa.)
I ran some additional tests and found that there are 255 values that produce incorrect results.
range_start | range_end | range_size | bsr_correct | bsr_SunsetQuest3 |
---|---|---|---|---|
33554431 | 33554431 | 1 | 24 | 25 |
67108862 | 67108863 | 2 | 25 | 26 |
134217724 | 134217727 | 4 | 26 | 27 |
268435448 | 268435455 | 8 | 27 | 28 |
536870896 | 536870911 | 16 | 28 | 29 |
1073741792 | 1073741823 | 32 | 29 | 30 |
2147483584 | 2147483647 | 64 | 30 | 31 |
4294967168 | 4294967295 | 128 | 31 | 0 |
In all of these these cases, the value is rounded up during the float conversion (tested in LINQPad 6, which is .NET Core).
This is the routine I used to generate my test cases:
static IEnumerable<uint> GenerateInputs32()
{
yield return (1U);
yield return (2U);
yield return (3U);
uint x = 4U;
uint y = 6U;
for (int i = 1; i < 31; i++)
{
yield return (x);
yield return (x + 1);
yield return (y);
yield return ((x << 1) - 1);
x <<= 1;
y <<= 1;
}
}
This tests all powers of 2, all values one less than a power of 2, all values one greater than a power of 2, and all values halfway between two powers of 2.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.