Skip to main content

Questions tagged [integer]

Use this tag for questions about using, storing or manipulating integral values of all types and sizes, including concerns about overflow. Not for code that casually happens to use integers.

Filter by
Sorted by
Tagged with
3 votes
2 answers
849 views

Intro In this post, I will present three (3) non-negative integer encoding techniques: Elias gamma coding Elias delta coding Golomb-Rice coding Code ...
coderodde's user avatar
  • 32.3k
5 votes
1 answer
407 views

I have implemented an elementary positive integer class that supports addition, subtraction, and multiplication for an arbitrary number of digits using a singly linked list. ...
Kushagr Jaiswal's user avatar
5 votes
2 answers
849 views

Intro This time, I have attempted to prove the following bruteforce multiplication formula: $$ (a_n \cdots a_0) \cdot (b_m \cdots b_0) = \sum_{i = 0}^n \sum_{j = 0}^m a_i b_j \cdot 10^{i + j}, $$ ...
coderodde's user avatar
  • 32.3k
13 votes
5 answers
3k views

This is my infinite precision integer implemented in C++20. It supports negative numbers. I have implemented addition, subtraction, multiplication and binary integer division, which returns quotient ...
Ξένη Γήινος's user avatar
-4 votes
1 answer
393 views

[edit] Hint: a similar project for C++20 which - as far as I see - also manages bigger than 128-bit integers can be found at: Infinite precision integer in C++20 . [/edit] I got lots of kind hints on ...
user1018684's user avatar
3 votes
3 answers
621 views

I got helpful reviews for first steps in: int128 handling in c-code, gcc / glibc / linux, int128 handling in c-code, gcc / glibc / linux - follow up and int128 handling in c-code, gcc / glibc / linux -...
user1018684's user avatar
3 votes
1 answer
254 views

An update to Int128 That is built on Linux for lack of direct support, based on System.Numerics Nuget package. ...
Short Int's user avatar
  • 762
3 votes
2 answers
909 views

I got very nice reviews for an attempt to produce read and print routines for 128-bit integer datatypes in: int128 handling in c-code, gcc / glibc / linux and: int128 handling in c-code, gcc / glibc / ...
user1018684's user avatar
4 votes
1 answer
249 views

I have created Int128 which is based off of BigInteger with operator overloading to handle larger math requirements. Here is a ...
Short Int's user avatar
  • 762
5 votes
2 answers
415 views

I had a draft for int128 handling reviewed there: int128 handling in c-code, gcc / glibc / linux I changed a lot according to the hints there, while leaving in, e.g., a trailing space on each line, ...
user1018684's user avatar
3 votes
0 answers
130 views

I have this repository. It contains three variations of a simple sorting algorithm for integer keys. The idea is that we keep a balanced BST in which each node holds the integer key and its frequency. ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
263 views

I used std::multiset to determine how many times that factor appears. I'd like to know if it can be improved; I've focused on the algorithm rather than the code. ...
ozan's user avatar
  • 53
2 votes
1 answer
186 views

As Java programmers, we can always use the BigInteger isProbablePrime() method or store manually all prime numbers in a HashMap. This question is about the most efficient way to figure out if a single ...
user3595831's user avatar
6 votes
2 answers
333 views

I have a very hot segment of code in a large project. I've extracted the relevant segment and a toy example to illustrate it. The project involves an unavoidable combinatorial explosion related to ...
Dave's user avatar
  • 163
3 votes
2 answers
338 views

This is a follow-up question for conv2 Template Function Implementation for Image in C++ and An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. For performing ...
JimmyHu's user avatar
  • 7,575
5 votes
0 answers
115 views

(The entire project is here.) Intro I have this priority queue data structure for non-negative integer priority keys. I recall that it is called Dial's heap. Code Implementation ...
coderodde's user avatar
  • 32.3k
9 votes
3 answers
1k views

I'm learning C and as exercise I'm trying to implement a custom function to parse a input from user and return successfully only if the input is a number. These are my files, how could I improve it? ...
shark_sh's user avatar
6 votes
1 answer
320 views

I have an interest in how the number of ways you can reach from the origin to a certain distance on both square and hexagonal lattices. If L is the square of the distance and integer pairs (i, j) are ...
uhoh's user avatar
  • 605
1 vote
1 answer
175 views

Problem: According to a recent survey, Biryani is the most ordered food. Chef wants to learn how to make world-class Biryani from a MasterChef. The chef will be required to attend the MasterChef's ...
kvk30's user avatar
  • 113
5 votes
1 answer
305 views

I coded stuff for an embedded device where int is 24bits. I wanted to port uint24_t and ...
Vortex 2728182818's user avatar
3 votes
1 answer
148 views

This class is meant to work exactly as an unsigned integer should work, but it limits the value based on a set amount of bits. ...
RhinoRunner's user avatar
6 votes
2 answers
247 views

The class below implements an arbitrarily sized whole number C++ class. It is wrapped around a bitvector class, which does most the binary heavy lifting. The basic ...
StormCrow's user avatar
  • 369
0 votes
1 answer
43 views

I would like to refactor the following code snippet adapted from a project I'm involved. It is part of a code to control power outlets via network. The code snippet was written by myself based on the ...
Looser User's user avatar
2 votes
1 answer
200 views

The purpose for this class is to pack two 4 bit unsigned integer into 8 bit unsigned integer, e.g. uint8_t. It is made in a way, so the class to resemble array of ...
Nick's user avatar
  • 1,656
6 votes
2 answers
213 views

I made a borders filter in C. It works properly, but I think it could be optimized and better designed; the formatting is abysmal. It uses too many lines for the border cases and has too many ...
GBA's user avatar
  • 63
4 votes
2 answers
310 views

This is an x86-64 Linux program to print a non-negative decimal integer. I would appreciate any simple optimizations for size and readability. I am aware that division by a constant is usually done by ...
qwr's user avatar
  • 1,233
1 vote
3 answers
220 views

I've a simple push/pop implementation in my program: ...
3rdgrade-dropout's user avatar
6 votes
2 answers
6k views

When working on my projects, I often need a 128-bit integer type. For this purpose, I use the __int128 compiler extension. Here is the implementation I am currently ...
DaBler's user avatar
  • 309
3 votes
1 answer
383 views

I have implemented an integer square root function that is branch-free and runs in constant time, using the first variant found in this answer as a base. All possible values for the types ...
Kittoes0124's user avatar
  • 1,960
1 vote
2 answers
534 views

I have this switch case statement which maps an integer to a string. There can be multiple integers that maps to same string. objective here is to not to duplicate the string value and retrive the ...
Pahan's user avatar
  • 21
8 votes
4 answers
3k views

If this code is written correctly, it will block undefined behavior from happening in the case of signed overflow (guaranteeing that the program halts instead), and also guarantee that the program ...
Thisis Afal Sename's user avatar
3 votes
1 answer
529 views

Integers need to be converted to a byte array of defined endianness to be reliably and consistently saved and transmitted, and converted back to be accurately received and read. The goal is to be as ...
CPlus's user avatar
  • 1,467
4 votes
1 answer
711 views

Is it a bad thing to use asserts to validate user inputs? Or should I keep using an if statement in case the number isnt positive? Code with assert statement: ...
eddyxide's user avatar
  • 141
2 votes
1 answer
128 views

I am implementing a generic absolute value function that handles signed and unsigned integer values correctly over the input type's domain. The std::abs(...) ...
dvnlo's user avatar
  • 153
6 votes
4 answers
2k views

This code was a challenge from a friend. Essentially she wanted a way to "Divide an even number into 2 even numbers." So I made this quick and dirty Python program to find the solutions up ...
Omar Morales Rivera's user avatar
1 vote
1 answer
75 views

I needed a set with the following properties: can be iterated in ascending or descending order in \$O(N)\$ time the usual set operations (contains, add, remove, discard) can still be done in \$O(1)\$ ...
joseville's user avatar
  • 516
5 votes
2 answers
1k views

The problem goes like this: Given two one-dimensional arrays, for example a = (3, 4, 5) and b = (5, 6, 9), write a function ...
Eugene Yarmash's user avatar
1 vote
4 answers
310 views

Now, I have extended my program taking some answers in the previous iteration into account: ...
coderodde's user avatar
  • 32.3k
5 votes
4 answers
2k views

(See also the next iteration.) I have rolled this short program that converts int values to the human readable strings: ...
coderodde's user avatar
  • 32.3k
1 vote
1 answer
2k views

This function creates takes an int * buffer and creates a neatly formatted string (useful for printing the contents of an array). Is the code easy to follow? Is it ...
cgoates's user avatar
  • 185
0 votes
1 answer
246 views

The context is a library to represent numbers (in this case integers) by wheighted position by radix powers for every radix R, passed as template argument. These derived types are digits of radix R, ...
Earendil's user avatar
3 votes
1 answer
78 views

Do you have any criticisms or corrections or improvements? I need to read only numbers(and this numbers could be from 0 to 1000000) ...
Оля Швенда's user avatar
2 votes
1 answer
250 views

I want to encode a non-negative integer to ASCII letters and digits. I wrote below code for that, that works, but which I assume too immature to use in production. ...
user avatar
1 vote
1 answer
90 views

Below is a C code that generates 1000 random positive integers, for each number we check primality, palindromic property, and the square root of the sum of the digits. The purpose is to find/discover ...
Redsbefall's user avatar
  • 1,212
3 votes
1 answer
3k views

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
Ola Ström's user avatar
19 votes
4 answers
4k views

I'm writing a minimal C runtime targeting an old 32-bit Windows XP machine as a personal project. The C runtime provided by compilers is quite bloated. I wouldn't mind some library bloats up to ...
xiver77's user avatar
  • 419
4 votes
3 answers
1k views

I wanted to get my code reviewed as I have tried to implement a basic Money class to represent money values in c++. Can anyone tell me if I am implementing my basic arithmetic operator overloads ...
paigelarry342's user avatar
6 votes
3 answers
2k views

As already written in the title I want to count the numbers in the range (x+1, y) where x and y are integers, in which the sum of the digits in odd places have the same parity of the ones in even ...
DarkSkull's user avatar
  • 163
0 votes
3 answers
932 views

...
nates7's user avatar
  • 1
2 votes
3 answers
929 views

I have attempted [and made one] function to convert string to integer and catch errors in pure c Working method The whole working method is present in code itself The header file The str2num.h here:- <...
Pear's user avatar
  • 77

1
2 3 4 5
8