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)
133 Views Asked by user1172131 At
1
There are 1 best solutions below
Related Questions in C
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in MODULE
- Magento custom block. Can't get block's file
- Undefined is not a function when calling node module
- Why is it bad practice to use from module import *?
- Node.js http.get example
- Perl Module using %EXPORT_TAGS
- Yii, Load a model of a module from the main app controller
- Ocaml unbound type constructor with module
- Drupal location module shows only a portion of Gmap on node page
- phpinfo() uses old version. What am I missing after "make install"?
- Accessing 2 different tables from same controller file
- Do software engineers in general have no idea about Software Architecture Design?
- Class Path entry my.jar does not point to a valid jar for a Class-Path reference
- TypeScript: workaround for relative reference path?
- Python - Can't install modules on mac
- Text file not being imported with module
Related Questions in OVERFLOW
- How to make nested div scrollable when parent is too small on x axis?
- Python RuntimeWarning overflow encountered in double_scalars
- Bootstrap Thumbnail Cropping and Positioning
- Div overflowing
- Inner Div overflow issue?
- Allow absolutely positioned child to render outside parent with overflow: hidden
- Overflow visible on text input, is it possible?
- VBA Override Error 6 Overflow (Create Infinite Loop)?
- HTML & CSS - Absolute positioned div overflows relative div, unexpected result
- HTML / CSS : hide overflow of fixed height div in pdf print
- Ensure vertical content overflows horizontally
- Overflow-y and Fixed Positioned Bug Fix in Internet Explorer
- Setting overflow: scroll on a table with display: flex
- Bug in Chromium with rendering css transformation transition
- position sticky polyfill with overflow support
Related Questions in MODULAR-ARITHMETIC
- how - 5%3 is equal to - 2?
- C++ Number theory: Fastest way to compute max(y = a_i * x+ b_i) <= k
- Fast modular multiplication modulo prime for linear congruential generator in C
- Calculating modulus for larger numbers in python
- Modulo operation difference between Swift and Python
- How to implement modular exponentiation that requires at most double the bytesize of the number that is to be modularly exponentiated in C?
- How to create a typesafe range-limited numeric type?
- Modular arithmetic (a*b/e)%m?
- How to find antilogarithm for large values?
- Calculating the Modular Inverse in JavaScript
- Solving modular equations in maple
- Smart modular multiplication using BigInteger Java
- How to do arithmetic modulo another number, without overflow?
- Left to right binary modular exponentiation in Javacard
- Modular arithmetics and NTT (finite field DFT) optimizations
Related Questions in INT128
- __uint128_t not working with Clang and libstdc++
- __int128 supported by emscripten? If not, how to implement 128 bit int multiplication?
- How to print __int128 in g++
- An efficient way to do basic 128 bit integer calculations in C++?
- How to use 128 bit integers in Cython
- Converting large integer (uint64+) into hex
- Multiplication of 2 positive numbers in Julia gives a negative product
- C# BigInteger with Decimal outcome
- How to bit scan forward and reverse a __uint128_t (128bit)?
- Numpy octuple precision floats and 128 bit ints. Why and how?
- asm x86_64 Intel Linux - Move RDX:RAX into XMM0
- use of 128 bit unsigned int in c language
- c code: prevent overflow in modular operation with huge modules (modules near the overflow treshold)
- ASM/NASM - Return high low of a MUL in a type struct
- In C#, how do I extract the two UInt64 values that make up a UInt128?
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 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).