In my c code I have to perform a series of recursive modular operations. In particular I have to perform operations like (A*B)modC, with C~2^126, and A,B that, in principle, could be very big numbers (from 0 to 2^128 - 1) ( I work with 128 bit unsigned __int128 variables).
The problem is how to perform the module during the multiplication process. I need this because if the module is performed after the multiplication, I could exceed 2^128 (if A and B are very big) during the multiplication and corrupt the successive modular operation.
So I'd like to perform a multiplication which restart from 0 every time that I pass C (during the multiplication process) instead of every time I pass 2^128 - 1.
How should I do this?
c code: prevent overflow in modular operation with huge modules (modules near the overflow treshold)
136 Views Asked by user1172131 At
1
There are 1 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in MODULE
- (in promise) TypeError: NetworkError when attempting to fetch resource
- Cannot load modules/mod_dav_svn.so into server
- Not reading the function in a JavaScript Module file, by calling onclick in the html document
- Adding Modules to a Namespace using IIFE
- Preparing metadata (pyproject.toml) ... error
- I want to understand modularity in java. When compiling my app I have a ResolutionException
- ModuleNotFoundError: No module named 'src' while importing logging
- Nest.js can't resolve dependencies of the external library's Reflector dependency
- Npm build error: "Module not found: Error: Can't resolve './component/intro' in
- problemas con los CORS en .net core 7 y angular 15
- how can i fix this :ModuleNotFoundError
- A given package is installed but spyder won't see it
- Should I even continue trying to import a module from the parent package?
- Linking errors with includes in C++ nested modules
- Export and create package of c++20 modules
Related Questions in OVERFLOW
- CSS scrolling only on part of website - Flexbox, sidebar
- Values getting Overflowed while converting Bit into TB
- enable overflown data visible outside the container
- How to prevent overflowing border creating a horizontal scroll bar?
- Useless horizontal scrollbar in Firefox with absolute positioned div with fixed height
- Verilog Implementation: Detecting Overflow and Rolling Up Result
- text-overflow: ellipsis not working when italic text overflows only one side of the container
- Text overflow in Flutter localization with easy_localization package
- Is there anyway to have containers maintain border radius when being scrolled off screen?
- Trying to build a dashboard using chakra UI
- react-scroll doesn't work with tailwind overflow-y-scroll using Next.js
- Scrollbar is visible but scrolling is not working (y-axis)
- Extended Text for applying ellipses in middle for text widget
- VBA Overflow error 6 on excel barcode scanning sheet?
- How to solve content overflow issues when you have too many items and why is media queries not working?
Related Questions in MODULAR-ARITHMETIC
- How to calculate efficient binominal coefficient or sum of these coeficients mod value?
- Replacing counter with a function
- How to perform integer modular exponentiation in Golang
- How to do modular arithmetics on big numbers in Swift?
- How long will this modular exponentiaton need?
- Implementing Montgomery ladder methods for modular exponentiation in python
- How would I solve a linear Diophantine congruence in Python?
- Modular Exponentiation Big O Notation
- Is there a modulo function with offset in Python?
- RSA - CTF Encrypt and Decrypt
- Find all possible sets of variables a, b, c which fits these two equations
- Find the combination of coin chips by minimising the value of E=4N + 0.3n
- Find a multiplier which multiplies given indices into a formation of bits
- Square number multiple times
- Modular Exponentiation using mips
Related Questions in INT128
- Converting large integer (uint64+) into hex
- .NET 8.0: Int128 and Uint128 equivalent in JSON?
- Can I access the two 64-bit registers in __uint128_t separately?
- How to use the C library "_int128_t.h" in Cython
- Squaring 2**32 into a 128-bit type fails
- Why does gcc give a warning saying that the constant is unsigned because it is too large, when it is of the type __int128 and is signed?
- Cannot overload std::abs() for GCC 128 bit integer
- Output 128 bit integer using stream operator
- In C#, how do I extract the two UInt64 values that make up a UInt128?
- ASM/NASM - Return high low of a MUL in a type struct
- Faster way to add an `__int128` to an `mpz_class` or `mpz_t` of the GMP library?
- How to write 128Int or 256Int to Buffer in nodejs
- Multiplication of 2 positive numbers in Julia gives a negative product
- asm x86_64 Intel Linux - Move RDX:RAX into XMM0
- Square root of a u128
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The naive solution is to implement multiplication as a loop over bits, shifting by one and adding each time. This way you can compute the modulus of the interim result each pass through the loop.
It requires 128 shifts, 128 additions and 128 modulo operations. If that is too slow for you then some boffin can probably tell you an optimization (but everyone knows you should only consider optimization once you are sure that the simplest solution isn't fast enough).