biginteger

Bug in Number or BigInteger and BigDecimal (or alternatively in the API documentation of those)?

旧街凉风 提交于 2020-01-04 05:42:12
问题 According to the specification of Number.longValue() the method should... Returns the value of the specified number as a long. This may involve rounding or truncation. However, the BigInteger (and BigDecimal ) overrides this method and returns the 64 low bits of the integer part of the number it represents. From the docs of BigInteger for example: [...]if this BigInteger is too big to fit in a long, only the low-order 64 bits are returned.[...] I claim that either " This may involve rounding

How to use IntInf or LargeInt in SML?

我只是一个虾纸丫 提交于 2020-01-04 05:07:34
问题 I want to to perform computations with large integers in SML, through functions like pow in this link: http://www.standardml.org/Basis/int-inf.html#IntInf:STR:SPEC But how do I get to use this "library"? UPDATE: Thanks for the answer. I got it. I also had to change the limit for printing with Control.Print.intinfDepth := 10000; I made my own pow function for IntInfs (and it works) like this: fun power 0 = IntInf.toLarge 1 | power n = IntInf.toLarge 2 * power(n-1); 回答1: It depends on which

Integer with 24 digits

痴心易碎 提交于 2020-01-03 10:44:12
问题 To check some bank account numbers I want to do a modulo 97 on an account number. But a lot of account number is to big to enter in a UInt64. How can I do an opperation on a 24 digits integer ? Thanks, Sample code (it can't convert) : (Convert.ToUInt64("756842356987456214536254") % 97 == 1); 回答1: One way would be to use System.Numeric 's BigInteger: BigInteger bi = BigInteger.Parse("756842356987456214536254"); 回答2: Thanks, It's work. Org.BouncyCastle.Math.BigInteger bi = new BigInteger(

making an array of bigInteger of size biginteger in java

流过昼夜 提交于 2020-01-03 05:34:08
问题 i am trying to make an array of biginteger of size biginteger. public class Polynomial4 { private BigInteger[] coef; private BigInteger deg; public Polynomial4(BigInteger a,BigInteger b) { coef = new BigInteger[b+1];// here its giving the error coef[b] = a; // here also its showing error * ///required int found Biginteger } } please help me....thanks in advance.... 回答1: BigInteger has an intValue method. which converts BigInteger into an int primitive.arrays expect an int as its size while

BigIntegers, gcd , modulus inverse to find public key

狂风中的少年 提交于 2020-01-02 17:20:53
问题 So, Im using java to find the public key of a RSA password. Right now Im unsure what I'm doing and also if it's correct. I have this information for the public key. C = 5449089907 n = p*q = 8271344041 q = 181123 p = n/q = 45667 d = 53 phi(n) = (p-1)(q-1) = 8271117252 What complicates things are the BigIntegers, the numbers are way to huge for int and longs, so I have to use the clumsy BigIntegers. As far as I understand I have the following equation to solve. e*5198987987 - x*8271117252 = 1 I

Parallel calculation of BigInteger factorial

五迷三道 提交于 2020-01-01 07:03:07
问题 As a part of my BigDecimal library, I need to calculate the factorial of any given non negative integer. So I'm using .Net 4.0 's System.Numerics.BigInteger to be able to store huge numbers. Here is the function I'm using: private BigInteger Factorial(BigInteger x) { BigInteger res = x; x--; while (x > 1) { res *= x; x--; } return res; } It's working but not optimized. Now I want to use parallel computing, so here is what I've tried: (I have no experience with parallel programming) public

SHA256 Hash results different across Android & iOS for Big numbers

时光怂恿深爱的人放手 提交于 2019-12-31 22:39:35
问题 I'm trying to Hash a BigInteger/BigNum and I'm getting different results in Android/iOS. I need to get the same Hash result so that both the apps work as per the SRP protocol. On closer inspection it is working fine for positive numbers but not working for negative numbers (first nibble greater than 7). Not sure which one is correct and which one is to be adjusted to match with the other. Android: void hashBigInteger(String s) { try { BigInteger a = new BigInteger(s, 16); MessageDigest sha =

How to save/load BigInteger array

早过忘川 提交于 2019-12-31 07:34:09
问题 I want to save/load a BigInteger array into/from the SharedPreferences. How can it be done? For example for the following array: private BigInteger[] dataCreatedTimes = new BigInteger[20]; 回答1: Using Gson you can convert to a json String and back, which then of course makes it trivial to save in preferences: import com.google.gson.Gson; import java.math.BigInteger; public final class BigIntegerArrayJson { private BigIntegerArrayJson(){} public static String toJson(BigInteger[] array) { return

Fibonacci calculator with BigIntegers

岁酱吖の 提交于 2019-12-31 04:11:52
问题 I'm working on a homework project where I must have the user input a number, and the computer spits out the Fibonacci numbers up to that one. I'd normally be able to do this, with int values, except that for this program, I need to use the BigInteger type instead, because int, long, double, etc. types are too small to hold the values I'll need. So, this is the code I've got. The problem is that it doesn't print the numbers it's supposed to. My imports: import java.math.*; import java.util

Fibonacci calculator with BigIntegers

天涯浪子 提交于 2019-12-31 04:11:48
问题 I'm working on a homework project where I must have the user input a number, and the computer spits out the Fibonacci numbers up to that one. I'd normally be able to do this, with int values, except that for this program, I need to use the BigInteger type instead, because int, long, double, etc. types are too small to hold the values I'll need. So, this is the code I've got. The problem is that it doesn't print the numbers it's supposed to. My imports: import java.math.*; import java.util