Division
In mathematics, division (÷) is an arithmetic elementary operation.
Subtraction
Subtraction is a mathematical operation that represents the removal of an object from a collection.
Precedence higher operator
Example |
---|
"Without parentheses math.exp c b is executed first as division has higher precedence than subtraction -" from question Actionscript calculates erroneous division without brackets |
"That s because the division operator has a higher precedence than the subtraction operator -" from question Bad value in calculation output "Remember multiplication division and remainder operators are all higher precedence than subtraction" from question Other way to solve assigning "In this case division has higher precedence than subtraction parenthesis around the division or not" from question Why does C assume integer type within a calculation for a double? "Division has higher precedence than subtraction so in the first two examples only the second number is being divided" from question Ruby math issue with division "Division has higher precedence than subtraction" from question Complex calculation in JavaScript |
"This is because division operator has higher preference than the subtraction operator - in the first example you use are not using brackets therefore division takes place first you can change your code to" from question Random output from forumla in C |
"Because the division operator has higher precedence than subtraction" from question Convert HSB/HSV color to HSL |
"I don t think they have a natural precedence unlike say multiplication and division being of greater precedence than subtraction and addition because they can be built from subtraction and addition" from question Bitwise operators order of precedence "In this since division has greater precedence than subtraction therefore x 10 will execute first and here we are dividing two int irrespective of the fact that the variable where final answer is stored is a double so answer will be an int i.e 5 10 0 and then subtraction of an int and double will be done here int will be promoted to a double" from question Java primitive types promotion confusion |
"Usually simple operations like addition subtraction and multiplication are very fast;division is a bit slower" from question How do I measure the FLOPS my C# app uses? |
"Doesn t get evaluated the way you are expecting the division operator has higher precedence than the subtraction operator" from question How many hours have passed |
Slower reduction n
Example |
---|
"The division operation binds tighter than i.e is evaluated ahead of the subtraction so you are taking a square root of a negative number" from question Why am I getting imaginary numbers instead of a simple answer |
"This is called a strength reduction optimization because division is stronger slower more expensive than subtraction" from question Assembly language making a for loop that runs n/10 times |
"This is called a strength reduction operation because subtraction is a weaker and cheaper operation than division" from question How do initialize an SIMD vector with a range from 0 to N? |
"Again this is not ambiguous once you know what the terms of reference are but beware of incorrectly comparing the first analysis i gave of euclid s algorithm with division o n 2 against this analysis of the algorithm with subtraction o n;n is not the same in each and subtraction is not faster" from question Algorithm complexity with input is fix-sized |
"I am a bit suspicious of the performance because modulo tends to use division which is slower than your subtraction operations" from question Calculate difference between multiples of two different numbers |
Unsigned 64-bit 32-bit
Example |
---|
"Unsigned division of 64-bit division by 32-bit divisor by repeated subtraction of divisor from dividend with remainder may be faster than regular division if the dividend is not expected to be much bigger than the divisor" from question How can I do 64 bit division on linux kernel? |
"Floating point number division is faster than integer division because of the exponent part in floating point number representation;to divide one exponent by another one plain subtraction is used" from question Why float division is faster than integer division in c++? |
Others
Example |
---|
Division requires iterative subtraction that cannot be performed simultaneously so it takes longer;in fact some fp units speed up division by performing a reciprocal approximation and multiplying by that from question Multiply by 0.5 rather than divide by 2 |
If you re on an embedded cpu where division is more expensive you can accomplish exactly the same thing like this the total amount added to accum here is just like the first example but the division is replaced with an incremental repeated subtraction from question Evenly space n items over m iterations |
This platform is probably not representative of your microcontroller but the test shows that on this platform the subtraction is considerably slower than the division from question Converting to ASCII in C |
Subtraction is similar using subtraction of the base type and borrow instead of carry multiplication can be done with repeated additions very slow or cross-products faster and division is trickier but can be done by shifting and subtraction of the numbers involved the long division you would have learned as a kid from question Arbitrary-precision arithmetic Explanation |
It may not be the most elegant method but when you just need to convert something ad-hoc thinking of it as comparison and subtraction may be easier than division from question Is it possible to use logarithms to convert numbers to binary? |
Similar to sam westrick s definition number of times you can subtract n2 from n1 without going negative you could also do integer division with addition and greater-than using the definition number of times you can add n2 to integer division before integer division is greater than n1 .;addition might seem like a conceptually simpler thing than subtraction from question How can I divide two numbers in ML defined as a datatype? |