Questions tagged [divide]

Separate or be separated into parts

Separate or be separated into parts

688 questions
701
votes
48 answers

Divide a number by 3 without using *, /, +, -, % operators

How would you divide a number by 3 without using *, /, +, -, %, operators? The number may be signed or unsigned.
Green goblin
  • 9,898
  • 13
  • 71
  • 100
162
votes
12 answers

Find if variable is divisible by 2

How do I figure out if a variable is divisible by 2? Furthermore I need do a function if it is and do a different function if it is not.
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
120
votes
8 answers

Why does Decimal.Divide(int, int) work, but not (int / int)?

How come dividing two 32 bit int numbers as ( int / int ) returns to me 0, but if I use Decimal.Divide() I get the correct answer? I'm by no means a c# guy.
user4903
78
votes
12 answers

How do I divide in the Linux console?

I have to variables and I want to find the value of one divided by the other. What commands should I use to do this?
kman99
  • 7,315
  • 4
  • 24
  • 20
65
votes
5 answers

Divide two variables in bash

I am trying to divide two var in bash, this is what I've got: var1=3; var2=4; echo ($var1/$var2) I always get a syntax error. Does anyone knows what's wrong?
Mathias Verhoeven
  • 927
  • 2
  • 10
  • 24
59
votes
9 answers

Divide and Get Remainder at the same time?

Apparently, x86 (and probably a lot of other instruction sets) put both the quotient and the remainder of a divide operation in separate registers. Now, we can probably trust compilers to optimize a code such as this to use only one call to…
Ben
  • 7,692
  • 15
  • 49
  • 64
38
votes
2 answers

Python Class __div__ issue

The tuples represent fractions. I'm trying to divide the fractions by multiplying by the reciprical class Test(): def __init__(self): self._x=(1,2) def __div__(self,div_fraction): return…
user3295426
  • 381
  • 1
  • 3
  • 3
34
votes
3 answers

How to convert milliseconds to seconds with precision

I want to convert milliseconds to seconds (for example 1500ms to 1.5s, or 500ms to 0.5s) with as much precision as possible. Double.parseDouble(500 / 1000 + "." + 500 % 1000); isn't the best way to do it: I'm looking for a way to get the remainder…
Keir Nellyer
  • 913
  • 5
  • 12
  • 20
32
votes
2 answers

numpy divide along axis

Is there a numpy function to divide an array along an axis with elements from another array? For example, suppose I have an array a with shape (l,m,n) and an array b with shape (m,); I'm looking for something equivalent to: def…
user545424
  • 15,713
  • 11
  • 56
  • 70
23
votes
4 answers

How do I get a float value when dividing two integers? (PHP)

Hi I am trying to divide two integers ex: 12/13 but I always get a whole integer 1 not a decimal number. I tried type casting the values to float before hand with no success. Basically all I want is a decimal result like: 0.923... $x = 12; $y =…
user1869257
  • 505
  • 2
  • 6
  • 16
23
votes
5 answers

Divide each data frame row by vector in R

I'm trying to divide each number within a data frame with 16 columns by a specific number for each column. The numbers are stored as a data frame with 1-16 corresponding to the samples in the larger data frames columns 1-16. There is a single number…
Ramma
  • 335
  • 1
  • 2
  • 6
21
votes
3 answers

Dividing two integers to a double in java

I can see this is a common problem for new programmers, however I didn't succeed in implementing any of the solution to my code. Basically I want to divide w and v, which must be saved to a double variable. But it prints [0.0, 0.0, ... , 0.0] public…
roarknuppel
  • 269
  • 1
  • 2
  • 8
19
votes
2 answers

How to handle meta data associated with a pandas dataframe?

Q1: What is the best practice for saving meta information to a dataframe? I know of the following coding practice import pandas as pd df = pd.DataFrame([]) df.currency = 'USD' df.measure = 'Price' df.frequency = 'daily' But as stated in this post…
quantguy
  • 237
  • 2
  • 10
19
votes
6 answers

Java Remainder of Integer Divison?

I was searching around about this topic but I still don't get it, if someone can elaborate I would be very thankful. My task is to divide two variables as integer division with remainder.. The problem is, that I have no clue what a remainder is, for…
DisasterCoder
  • 477
  • 1
  • 3
  • 17
18
votes
4 answers

Divide one list by another list

I have two lists like this: monkey = ['2\n', '4\n', '10\n'] banana = ['18\n', '16\n', '120\n'] What I want to do with these two list is make a third list, let's call it bananasplit. I have to strip away ' \n', leaving only values and then make a…
RasmusJ
  • 396
  • 1
  • 2
  • 10
1
2 3
45 46