biginteger

How to use operators for BigInteger

余生长醉 提交于 2020-06-29 05:13:08
问题 import java.lang.Math; import java.math.BigInteger; import java.math.BigDecimal; public class Main { public static void main(String[] args) { int e1 = 20, d = 13; BigInteger C = BigDecimal.valueOf(e1).toBigInteger(); BigInteger po = C.pow(d); System.out.println("pow is:" + po); int num = 11; BigInteger x = po; BigInteger n = BigDecimal.valueOf(num).toBigInteger(); BigInteger p, q, m; System.out.println("x: " + x); q=(x / n); p=(q * n); m=(x - p); System.out.println("mod is:" + m); } } I've

PHP gives incorrect results when formatting long numbers

半世苍凉 提交于 2020-06-27 06:49:25
问题 I am working with huge numbers for website purposes and I need long calculation. When I echo a long number I don't get the correct output. Example // A random number $x = 100000000000000000000000000; $x = number_format($x); echo "The number is: $x <br>"; // Result: 100,000,000,000,000,004,764,729,344 // I'm not getting the value assigned to $x 回答1: Your number is actually too big for php standard integers. php uses 64 bit integers which can hold values within range -9223372036854775808 ( PHP

C# BigInteger.ModPow bug?

南笙酒味 提交于 2020-06-08 16:23:52
问题 I'm using the .NET BigInteger class to perform some math operations. However the ModPow method is giving me the wrong results. I have compared it to Java which I think is correct: // C# var a = new BigInteger(-1); var b = new BigInteger(3); var c = new BigInteger(5); var x = BigInteger.ModPow(a, b, c); // (x = -1) // Java BigInteger a = new BigInteger("-1"); BigInteger b = new BigInteger("3"); BigInteger c = new BigInteger("5"); BigInteger x = a.modPow(b, c); // (x = 4) Is it a bug in the