Logarithm of a BigInt

In case you don’t want to return a BigInt, then the following might work for you too: function log10(bigint) { if (bigint < 0) return NaN; const s = bigint.toString(10); return s.length + Math.log10(“0.” + s.substring(0, 15)) } function log(bigint) { return log10(bigint) * Math.log(10); } function natlog(bigint) { if (bigint < 0) return NaN; … Read more

Big numbers library in c++ [closed]

The GNU Multiple Precision Arithmetic Library does what you want http://gmplib.org/ Gnu MP is a C library but it has a C++ class Interface and if you are interested only in big integers, you may just deal with mpz_class. Look at the sample below which I took from the page C++ Interface General int main … Read more

A realistic example where using BigDecimal for currency is strictly better than using double

I can see four basic ways that double can screw you when dealing with currency calculations. Mantissa Too Small With ~15 decimal digits of precision in the mantissa, you are you going to get the wrong result any time you deal with amounts larger than that. If you are tracking cents, problems would start to … Read more

JSON transfer of bigint: 12000000000002539 is converted to 12000000000002540?

The value is actually not exceeding the maximum numeric value in JavaScript (which is “only” 1.7308 or so). However, the value is exceeding the range of “integral precision”. It is not that the wrong number is sent: rather, it is that the literal 12000000000002539 can only be represented as precisely as 12000000000002540, and thus there … Read more

MySQL: bigint Vs int

The difference is purely in the maximum value which can be stored (18,446,744,073,709,551,615 for the bigint(20) and 4,294,967,295 for the int(10), I believe), as per the details on the MySQL Numeric Types manual page. Incidentally, the use of (20) and (10) is largely irrelevant unless you’re using ZEROFILL. (i.e.: It doesn’t actually change the size … Read more