js-choi / proposal-bigint-bit-length Goto Github PK
View Code? Open in Web Editor NEWDraft specification for BigInt bit length in JavaScript.
License: BSD 3-Clause "New" or "Revised" License
Draft specification for BigInt bit length in JavaScript.
License: BSD 3-Clause "New" or "Revised" License
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.
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
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.
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.