GithubHelp home page GithubHelp logo

js-choi / proposal-bigint-bit-length Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 112 KB

Draft specification for BigInt bit length in JavaScript.

License: BSD 3-Clause "New" or "Revised" License

HTML 100.00%

proposal-bigint-bit-length's People

Contributors

jlhwung avatar js-choi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jlhwung

proposal-bigint-bit-length's Issues

Bit length, useful for ordinary numbers?

I wrote this in the explainer:

In contrast to other operations – such as abs and sqrt from the BigInt Math proposal – the new bit-length API would probably be useful only on BigInts and not on ordinary numbers.

Is this really true? One potential use case for ordinary-number bit lengths might be conveniently determining whether an ordinary number integer will fit within e.g. an Int16Array.

Of course, this would be complicated by what to do with non-integer numbers (something to do with IEEE floating-point representation? truncate? throw a TypeError?).

Either way, before or even during Stage 1, it is worth explicitly considering bit lengths for ordinary numbers.

Negative integers and zero

I think, for math use cases, ceil(log2(abs(a)+1)) is better, but this may be not expected, different libraries do it differently:
mpz_sizeinbase in GMP ignores the sign;
Dart, Java and .Net use ceil(log2(-a))
, so may be negative bigint should cause exception

Result type

Should the result type should be a Number or a BigInt?

We should be consistent with how we treat lengths in the other BigInt operators. In particular, the answer should match the inverse operation: given a bit length, produce a BigInt of that size. That inverse operation is either 1n << length or 1n << length-1n depending on whether we choose the off-by-one version or not, but in either case it wants the length represented as a BigInt. So that points towards returning a BigInt.

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.