How to round up the result of integer division?

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java. If I have x items which I want to display in chunks of y per page, how many pages will...

Why does Python integer division yield a float instead of another integer?

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 2/2 1.0 Is this intended? I strongly...

Floating point division in a batch file

I need to do a floating-point division in a dos batch. I didn't find a way to do it. Something like this : SET /A Res=10/3 returns a integer number. Is it possible to do it ?

How to perform an integer division, and separately get the remainder, in JavaScript?

In JavaScript, how do I get: The whole number of times a given integer goes into another? The remainder?

Division without using '/'

Can anyone tell me an efficient approach to perform the division operation without using '/'. I can calculate the integer value in log(n) steps using a method similar to binary search. 115/3 57 *...

Find the division remainder of a number

How could I go about finding the division remainder of a number in Python? For example: If the number is 26 and divided number is 7, then the division remainder is 5. (since 7+7+7=21 and 26-21=5.)

math.Mod in Go returns integer part instead of floating-point remainder

Golang's math.Mod(10, 4) returns 2 -- ie. the integer part of division result 2.5 -- but shouldn't it be "the floating point remainder", that is, 0.5?

fixed point arithmetics in java with fast performance

I need to represent some numbers in Java with perfect precision and fixed number of decimal points after decimal point; after that decimal point, I don't care. (More concretely - money and...

Python thread pool that handles exceptions

I've been looking around a good implementation of a simple python thread pool pattern and really can't find anything that suits my needs. I'm using python 2.7 and all the modules I have found...

Fast exact bigint factorial

I have a fixed-point bignumber library and want to implement fast factorial with no precision loss. After some math tricks on paper I got this formula: (4N)!=((2N)!).((2N)!).{...

Separating the Digits in an Integer - exercise from Deitel's Java book

Exercise from Deitel's "Java How To Program" 10th edition: 2.30 (Separating the Digits in an Integer) Write an application that inputs one number consisting of five digits from the user,...

Newton-Raphson Division With Big Integers

I'm making a BigInt class as a programming exercise. It uses a vector of 2's complement signed ints in base-65536 (so that 32-bit multiplications don't overflow. I will increase the base once I...

Pair of points with distance divisible by integer

I came across an interview questions and despite the fact I've been trying to solve it on my own I think I need some help. I've got an array of integer numbers (positive and negative) representing...

How to sort Integer digits in ascending order without Strings or Arrays?

I'm trying to sort the digits of an integer of any length in ascending order without using Strings, arrays or recursion. Example: Input: 451467 Output: 144567 I have already figured out how to...

Can someone help me with my while loop?

Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 20: 20 10 5 2 1 #include <iostream> using...

Javascript modulo operator behaves differently from other languages

According to Wikipedia, the modulo operator (remainder of integer division) on n should yield a result between 0 and n-1. This is indeed the case in python: print(-1%5) # outputs 4 In Ruby: puts...

Overflow Error When Diving Large Numbers In Python

I am trying to use a code to look for Wilson Primes for a bit of fun and to get me back into the swing of coding, however, I found that when I try to divide 172! +1 By 173 it gives me an Overflow...

Python subprocess module: Catch exception from a child process in parent process

How to catch exception from a child process in the parent process. The child process is created using Python's subprocess.Popen() like so: division_by_zero.py print(1/0) parent.py import...

Looking for the fastest way to divide by 2

I've searched half the day and found some very interesting things about using fixed point data types and bit shifting in C++ to accomplish division operations while avoiding floating point math....

Vectorcast using IAR compiler for RL78

I'm just started to work with Vectorcast and IAR for RL78 compiler. I want to build an environment in vectorcast using IAR Compiler for RL78 Microcontroller. Code which is used for testing has...

Find/simplify overlapping modulo

I have some code solving today's "Advent of code part 2". https://adventofcode.com/ I have currently many hardcoded modulo conditions, is there any simple way to reduce the number of...

c integer division not returning correct quotient

my code (in the C language) is this: avg = round((r + g + b) / 3); r = avg; g = avg; b = avg; It should do the grayscale image effect. There are no syntax errors, but apparently avg, when...

Why does Python floor division return a float when the divisor and/or dividend is a float?

If I understand correctly, the return value for floor division is always a whole number, even if the dividend and/or divisor are not whole numbers, so why does it not always return an...

Given a sorted list of integers of length N, determine if an element x is in the list

The problem to solve is: Given a sorted list of integers of length N, determine if an element x is in the list without performing any multiplication, division, or bit-shift operations. Do this in...

Binary search, when to use right = mid - 1, and when to use right = mid?

I was working through this problem on leetcode https://leetcode.com/problems/leftmost-column-with-at-least-a-one/ and I cant think of an intuitive answer. Why is the right (or high) pointer...

dec2base with independent bits/digits calculation

Need MATLAB/Octave dec2base functionality function with independent bits/digits calculation algorithm (within integer logic, with no divisions, using modular arithmetic). Would be nice to have as...

Is it possible to implement the extended euclidean algorithm with unsigned machine words?

I'm trying to find a way to implement EEA using uint64_t in C, on a system that will not support 128-bit integers. The problem is that it seems like there is always a case where some variable or...

Replace maximum value of each row with mean

I want to replace maximum value for each row in the column with mean value for this row. the method i am using taking a lot of time for complete. i am using pandas DataFrame. replaced mean value...

238.Product of Array Except Self-Leetcode

I have been trying out this problem on leetcode. *238.Product of array except self* Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the...

ZeroDivisionError: as 'integer division or modulo by zero' but get as 'division by zero

I want to get the exception of ZeroDivisionError: as 'integer division or modulo by zero' but I get as 'division by zero'.How can I get that. can anyone explain? a=int(input()) b=[] for i in...