Giter VIP home page Giter VIP logo

fast-integer-log2's People

Contributors

sunsetquest avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fast-integer-log2's Issues

SunsetQuest3 is incorrect for some inputs

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.