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.
396 questions
3
votes
2
answers
844
views
Three non-negative integer encoding techniques in Java
Intro
In this post, I will present three (3) non-negative integer encoding techniques:
Elias gamma coding
Elias delta coding
Golomb-Rice coding
Code
...
5
votes
2
answers
849
views
Bruteforce integer multiplication in Java
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},
$$
...
-4
votes
1
answer
393
views
int128 handling in C code, gcc / glibc / linux - follow up IV [closed]
[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 ...
3
votes
1
answer
253
views
Int128 for handling large numbers bassed off of BigInteger update
An update to Int128 That is built on Linux for lack of direct support, based on System.Numerics Nuget package.
...
4
votes
1
answer
247
views
Int128 for handling large numbers based off of BigInteger
I have created Int128 which is based off of BigInteger with operator overloading to handle larger math requirements. Here is a ...
3
votes
0
answers
130
views
Comparing two Tree sort algorithm variations implemented in Java
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. ...
2
votes
1
answer
186
views
What is the most efficient way to figure out if a single number is prime for numbers from 2 up to 2,147,483,647 in Java?
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 ...
3
votes
2
answers
337
views
im2double and im2uint8 Functions Implementation for Image in C++
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 ...
9
votes
3
answers
1k
views
C function to read only numeric values
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?
...
1
vote
1
answer
174
views
Calculate the cost of Biryani lessons
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 ...
3
votes
1
answer
146
views
Any amount bits integer
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.
...
0
votes
1
answer
43
views
Mangle words to bytearray of lo/hibytes
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 ...
6
votes
2
answers
213
views
First attempt at making a sobel edge detection filter in c
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 ...
1
vote
3
answers
219
views
Simple stack of integers
I've a simple push/pop implementation in my program:
...
3
votes
1
answer
383
views
Generic Integer Square Root
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 ...
8
votes
4
answers
3k
views
Standard C overflow-safe arithmetic functions
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 ...
4
votes
1
answer
711
views
Python function: user input to get positive integer using assert
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:
...
6
votes
4
answers
2k
views
Find all ways to express each of a list of even numbers as the sum of 2 positive, even numbers
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 ...
5
votes
2
answers
1k
views
Sum numbers digit by digit
The problem goes like this:
Given two one-dimensional arrays, for example a = (3, 4, 5) and b = (5, 6, 9), write a function ...
5
votes
4
answers
2k
views
Converting int values in Java to human readable strings in English
(See also the next iteration.)
I have rolled this short program that converts int values to the human readable strings:
...
0
votes
1
answer
246
views
C++20 Wrapper class for an unsigned integer type and a templated derived class that codes modular arithmetic type
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, ...
2
votes
1
answer
250
views
Encode non-negative integer to a string of ascii letters and digits
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.
...
3
votes
1
answer
3k
views
Format an integer with space as thousand separator
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 ...
4
votes
3
answers
1k
views
C++ money class for basic banking application
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 ...
0
votes
3
answers
931
views