2,006 questions
Best practices
3
votes
6
replies
142
views
Avoiding array duplication in big integer routine
I am working on a multiplication routine in a big integer library in POSIX C99 with a signature of bigint_st *bigint_mul(bigint_st *dest, const bigint_st *a, const bigint_st *b). Many of the routines ...
1
vote
2
answers
109
views
How to parse JSON values with large numbers using zod?
Is it possible to parse a JSON string like '{id: 3458764513820541000}' using zod without resorting to an additional library like json-bigint?
0
votes
0
answers
51
views
How to manage c# BigInteger on MongoDB
I'm trying to manage BigInteger on MongoDB. I did a test, but it doesn't seem to work correctly.
It is supposed to have the following poco:
public class Poco
{
public string MyString { get; set; } =...
2
votes
0
answers
240
views
Is Karatsuba algorithm necessary?
I am developing an algorithm that multiplies large numbers. I am doing LeftLength x RightLength multiplications. Karatsuba algorithm does less multiplications. Currently, the algorithm is more ...
0
votes
0
answers
90
views
vb.net BigInteger and ensuring that values are read correctly
Private Sub routine()
Dim bytes() As Byte
Dim n As BigInteger = 1
Dim s As Integer = 1
If System.IO.File.Exists("resources.bin") Then
Dim fs2 = New IO.FileStream(&...
1
vote
0
answers
69
views
Why aren't there operator overloads for working with BigInteger and BigDecimal as part of the BigInteger and BigDecimal class imports?
...such as
infix operator fun BigInteger.plus(other: Int) =
this + other.toBigInteger()
infix operator fun Int.plus(other: BigInteger) =
toBigInteger() + other
infix operator fun BigInteger....
0
votes
0
answers
145
views
Question about Knuth's Algorithm D for division
I want to implement Knuth's Algorithm D for division on C (Link to Knuth's book, p272). In step "D4. [Multiply and subtract.]", it states:
if the result of this step is actually negative, (...
0
votes
1
answer
102
views
How do I convert hexidecimal to decimal using C# & BigInt?
I can reproduce this 1 line all the time & I'm thrown off why .Net 8 x64 is converting to a negative decimal. BigIntegers have to be used because of the hex sizes.
Conversion URL fact checking ....
0
votes
0
answers
110
views
The fastest MOD algorithm in C++ for extremely large uint_64_t numbers stored in an array
I am working with extremely large numbers and would like to verify my Karatsuba multiplication result ((2^136279841)-1)^2 which needs (532 344 * _m256i_epi64)^2 i.e. 4,258,752 uint64_t to store the ...
1
vote
1
answer
125
views
Bug in the normalization step of Knuth Algorithm D (TAOCP 4.3.1)?
Knuth Algorithm D, during the normalization step (D1), states to set d to (b-1)//v_hi where b is the basis (word size or half-word size) and v_hi is the upper limb of the denominator. Then multiply ...
1
vote
1
answer
81
views
Bounds for C# Generic Random Array Generator
I have written this block of code, in an attempt to create a generic random array generator (quite an interesting approach, if I must say so myself)
public unsafe class RandomArray<T> : ...
1
vote
1
answer
226
views
Find n-element in sequence. How to speed up the programm (time) for n > 10^6?
I think I have right algorithm, but when the values increase to 106 and more, I exceed the MEMORY or TIMELIMIT allowed. At first I tried to push the elements to a vector, then I changed the method to ...
5
votes
1
answer
183
views
Time complexity of this dynamic programming algorithm to get nth fibonacci number
I'm confused about the time complexity of this algorithm:
function fib(n)
if n = 0
return 0
else
var previousFib := 0, currentFib := 1
repeat n − 1 times // loop is ...
1
vote
1
answer
406
views
Enforce the use of Utf8JsonReader.ValueSequence for test purposes
I wrote my own BigIntegerConverter for JSON serialization/deserialization (.Net System.Text.Json)
In the Read method I checked if ValueSequence is used
...
string stringValue;
if (reader....
1
vote
0
answers
158
views
Why does `BigInt(n)` return a different integer than `n`? [duplicate]
JavaScript's number can represent 18446744073709552000:
> n = '18446744073709552000'
> Number(n)
18446744073709552000
> String(Number(n)) === n
true
So I would expect BigInt(...
-2
votes
1
answer
113
views
I can't get the original bytes out of a concatenated byte String in Rust
I've converted a file into bytes and have a vec/array of
[68, 114, 97, 109, 97, 116, 105, 99, 32, 115, 97, 120, 97, 112, 104, 111, 110, 101, 32, 112, 108, 97, 121, 115, 32, 73, 78, 32, 84, 72, 69, 32, ...
-1
votes
1
answer
62
views
What is this problem with computation of large integers? [closed]
The following equation is same as doing nothing to the integer
((as.bigz(27080235094679553)+1028)*2)/2 - 1028
However, the answer to this in console is 27080235094679552. To get the correct answer I ...
1
vote
2
answers
75
views
Convert to BigInteger
I want to rewrite this function code to BigInteger class in Java:
static int power(int x, int y, int p)
{
int res = 1; // Initialize result
while (y > 0) {
// ...
0
votes
0
answers
41
views
Working in frontend JS. Is there a clean way to prevent all request response large integers from being rounded
I'm returning a dictionary object to a web route. And annoyingly, my frontend JS is automatically rounding all the integer values in the response.json()
let currentUserId;
let path = "/account?...
0
votes
1
answer
129
views
How to convert BigInt array representation to the Integer representation?
I was working with a zk project. Using some renowned libraries in the field. I wanted to print the input variable with single value in decimal representation but it's printed as
Inputs: BigInt([...
2
votes
1
answer
278
views
Why is C# BigInteger not always the same bit length?
I am trying to generate 1024bits random numbers with this code:
var bytes = RandomNumberGenerator.GetBytes(128);
var number = new BigInteger(bytes);
But when I inspect my number using BigInteger ...
0
votes
1
answer
515
views
Is calculating BigInt.pow(&BigInt) possible?
I want to calculate:
let n1 = BigInt(256);
let n2 = BigInt(1024);
let n3 = BigInt(3);
let n4 = BigInt(40);
let res = n1.pow(n2.pow(n3) * n4);
let len = res.to_string().len();
I tried num crate, but ...
0
votes
0
answers
47
views
Spring Boot - BigInteger value in the response body is not correct
I have a field "old" with the data type BigInteger in Spring Boot.
Property in Entity:
@Column(name = "old")
private java.math.BigInteger old;
In the database, this field "...
0
votes
1
answer
185
views
Convert BigInteger to ULong in Kotlin
Given a BigInteger in Kotlin that is in the range between 0 and 2^64, how can I convert this BigInteger to a ULong? Kotlin provides toULong() extension methods only for Byte/Short/Int/Long/Float/...
0
votes
1
answer
60
views
Why does Julia BigInt iterative functions overflow?
Let's say I want to write the factorial function in Julia in the following recursive way:
FACTORIAL(n) = n==1 ? 1 : n*BigInt(FACTORIAL(n-1))
Doing so, it shows the following error when trying to ...
3
votes
1
answer
133
views
How to deal with big integers in Elixir NIFs
I wrote an implementation of quicksort in C as an Elixir NIF. I'm aware that there is a BIF for that, I'm just doing this to teach myself NIFs.
Now my code works so far, that is, I can call ...
0
votes
1
answer
3k
views
Go: convert big.Int to regular integer (int, int32, int64)
I assumed this would be a simple issue with abundant answers on the Internet. But that does not appear to be the case.
I need to convert a Go big.Int into a regular integer (e.g., int, int32, or ...
1
vote
1
answer
160
views
how to convert a big int to a double in C++
In C++, I want to get the square root of a big int. The number is less than the maximum integer represented as a double, so this approach should work. The ttmath library doesn't have a square root ...
0
votes
0
answers
49
views
Electron build decreases performance
In my current side project my code is performing a large amount of very simple computation on large numbers.
I'm using the library "[email protected]" to handle the large number aspect.
I'...
0
votes
0
answers
118
views
Why does GMP use a pointer at the end of struct instead of zero sized array or Flexible Array Member?
Most of the sites I've been reading state that a zero-sized array, single element array or Flexible Array Members is the way to go when a dynamic array is needed, but the definition of an integer in ...
-1
votes
1
answer
63
views
Conversion of Integer
How would I convert Int 623527832412487691 to Int 623527832412487691n without the number changing value
I don't want Int 623527832412487691 to turn to Int 623527832412487700 as apparently JavaScript ...
0
votes
0
answers
179
views
How to do modular arithmetics on big numbers in Swift?
This comes up when evaluating a rolling hash of a string by subtracting the old weight of a character and adding a new weight for a new character.
Python has infinite length digits and is able to ...
0
votes
1
answer
75
views
Sum of large numbers in java [duplicate]
import java.util.Scanner;
import java.math.BigInteger;
public class LargeSum {
public static void main(String[] args) {
Scanner inp=new Scanner(System.in);
int limit=inp.nextInt()...
0
votes
1
answer
79
views
BigInteger logical operation takes more time in subsequent loops C#
I have the below console application to check the time taken for doing a specific operation with BigInteger in C#.
using System.Diagnostics;
using System.Numerics;
Stopwatch timer = new Stopwatch();
...
0
votes
3
answers
147
views
How to prevent overflow when calculating min & max sum of the elements by excluding one element in the list
I need to find the minimum and maximum values that can be calculated by summing exactly (size - 1) elements in the arrays
Example:
arr = [1,2,3,4,5] minSum = 1+2+3+4 = 10 , maxSum = 2+3+4+5 = 14
...
1
vote
2
answers
169
views
Calculating a very large integer
How do I add two big integers, I have tried using arrays and it still has some bugs.
Ex: A 23 digit + 25 digit positive integer (2345235... + 34634235....)
I've tried using arrays to separate the ...
0
votes
1
answer
891
views
Could someone help me to create a HOOK in FASTIFY to automatically serialize these types of values in all app.ts endpoints?
Could someone help me to create a HOOK in FASTIFY to automatically serialize these types of values in all app.ts endpoints
I managed to solve the problem using .toString, but I wanted a way to do ...
0
votes
1
answer
1k
views
Multiplying float with BigInt in JavaScript? [duplicate]
By using this website
I can calculate for example
x = 0.28
y = 1e18
x * y = 280,000,000,000,000,000
How can I do this in javascript while x could be any number, including ints, and y could be any ...
0
votes
0
answers
3k
views
RSA Oracle - Getting the flag by using chosen ciphertext attack
I am trying to solve a simple RSA CTF challenge, but I am facing problems that go beyond the theory behind the attack (or at least I guess so). Basically, I have an oracle at disposal that will first ...
1
vote
1
answer
179
views
Rust generic function accepting both primitive and rug integers
I'm trying to write a generic function that operates on integers, which can accept either primitive integers or multiprecision ones (via rug). The tricky bit is that references to rug Integers have ...
1
vote
0
answers
119
views
Problem with using BigInteger type in C# code
I'm new to C# and I'm trying to write code for the Fibonacci sequence. I get an error when I use the BigInteger type in my code.
I would be grateful if you could help me solve this problem.
this is my ...
0
votes
4
answers
130
views
Are these Java long integer or BigInteger format numbers? IP2Location csv database
I have never used long integer or BigInteger format numbers in my Java code, and this aspect of the IP2Location databases does not appear to be documented. I need to know which it is, so that I can ...
5
votes
1
answer
196
views
Last n digits of BigInteger
I'm looking for fast way to get n last digits of number, represented as BigInteger, lets say, m.
Calculating m mod(10^n) (or converting to string) seems too expensive, because the sizes of n are ...
1
vote
2
answers
215
views
How can I add up two 25 digit numbers?
I'm trying to work on addition of about 25 digit numbers in C. The result I am getting is a little different from the expected, possible cause datatype.
/* Online C Compiler and Editor */
#include <...
0
votes
1
answer
1k
views
BigInteger numbers not passing to JSON object
I have a smart contract I am interacting with but I cannot seem to form a proper JSON object using these variables. I have been able to pull the data and log it, I've even been able to pull other data ...
0
votes
0
answers
138
views
java BigInteger - How does destructiveMulAdd convert a number to big endian magnitude?
I am doing this side project where I try to understand the internal implementation of some of the widely used utility classes in Java.
I want to know how BigInteger store's the number internally.
What ...
0
votes
2
answers
107
views
modulo gives wrong result for big number in Java
look at the below Java Code :
long a = (long) 10e9+7;
long b = (a * a);
System.out.println("b is " + b);
System.out.println("b%a is " + (b%a));
...
0
votes
1
answer
127
views
java - How does BigInteger convert Strings to its internal representation?
I am doing a little side project where I am delving into the implementation of some popular classes that we use in the Java Libraries.
The first on my list is BigInteger. I am interested in ...
0
votes
1
answer
87
views
Numerics BigInteger.Remainder (Mod) doesn't work with negative divisors
Consider the following equations:
10 % 3 = 1
10 % -3 = -2
10001 % 30 = 11
10001 % -30 = -19
C#'s System.Numerics.BigInteger Seems to produce positive results for negative divisors, as if ...
0
votes
1
answer
1k
views
How to fix incompatible operand with BigInteger and int
Im trying to create a program for the collatz conjecture, and I need it to work for bigger numbers. So, i tried to use the BigInteger class, but it seems to run into an error with the two types: ...