FAQ Database Discussion Community

## divide parallel arrays C++ [duplicate]

c++,arrays,integer-division,parallel-arrays
This question already has an answer here: Why does division result in zero instead of a decimal? 6 answers I have a question about dividing parallel arrays. I'm fairly new to C++. In my program I'm dividing parallel arrays (atBats[] and hits[], and storing the results in an empty...

## 32 bit signed integer division gives 0x7fffffff as quotient on PowerPC

c,integer-division,divide-by-zero,integer-arithmetic,ppc
I am debugging a production code written in C and its simplest form can be shown as - void test_fun(int sr) { int hr = 0; #define ME 65535 #define SE 256 sr = sr/SE; <-- This should yield 0 if(sr == 1) hr = ME; else hr = (ME+1)/sr;...

## Mechanics of 'x % y != 0' in C++

c++,modulus,integer-division
Can someone please explain the under-the-hood mechanics of x % y !=0 in C++? It evaluates to 0 if there is no remainder in integer division and it evaluates to 1 if there is any remainder of any amount. I find this to be quite useful, but I'd like to...

## Dividing integers by floats resulting in proportional integers

algorithm,integer,division,integer-division
Recently I've came across a hard problem solving while doing a project. And I'd like to ask you guys for a solution / algorithm to solve it, because I'm really struggling to think about a clever idea to do so. I have an arbitrary number of floats: f1, f2, ...,...

## How to count number of divisible terms without using modulus operator?

algorithm,math,modulus,integer-division
Given three numbers N, A and B. Find how integers in range from 1 to N are divisible by A or B. I can't use modulus operator from range 1 to N because N can be as large as 10^12 and then I would run out of allocated time for...

## Why does Python 3.x have unusual floored (integer) division behaviour?

python,integer-division
Since the Python integer division operator (a // b) always returns a value which can be safely stored in an int without losing precision (no matter of values for a and b), why is the following true? If one or both operands are of type float, this operator returns a...

## Overflow while doing multiplication

c++,c++11,integer-division
I want to calculate value of (N* N *(N+1)/2) mod M where this N can go upto 10^18 and M is at max up to 10^7. I tried to code it but don't know the reason that why it is overflowing. Here is my code : In main I do...

## Unexpected result when calculating a percentage - even when factoring in integer division rules

c,percentage,integer-overflow,integer-division
I am trying to express a battery voltage as a percentage. My battery level is a (global) uint16 in mV. I have a 16-bit CPU. Here is my code: static uint8 convertBattery(void){ uint16 const fullBattery = 3000; /* 3V = 3000mV */ uint8 charge; charge = ((battery*100)/fullBattery); return charge; }...

## How many values of a vector are divisible by 2? Use R

r,sum,logical-operators,integer-division
I have an ex. where I have to see how many values of a vector are divisible by 2. I have this random sample: set.seed(1) y <- sample(c(0:99, NA), 400, replace=TRUE) I created a new variable d to see which of the values are or aren't divisible by 2: d...