Programming questions that are significantly affected or best defined by the underlying mathematics of the problem.
Questions tagged [math]
286 questions
92
votes
26 answers
What does mathematics have to do with programming?
I just started a diploma in software development. Right now we're starting out with basic Java and such (so right from the bottom you might say) - which is fine, I have no programming experience apart from knowing how to do "Hello World" in Java.
I…
Rory
- 237
89
votes
7 answers
Why is negative zero important?
I'm confused about why we care about different representations for positive and negative zero.
I vaguely recall reading claims that having a negative zero representation is extremely important in programming that involves complex numbers. I've never…
jpmc26
- 5,489
78
votes
67 answers
Do you have to be good at math to be a good programmer?
It seems that conventional wisdom suggests that good programmers are also good at math. Or that the two are somehow intrinsically linked. Many programming books I have read provide many examples that are solutions to math problems, or are somehow…
Charles Roper
- 1,363
75
votes
10 answers
Is it good practice to replace division with multiplication when possible?
Whenever I need division, for example, condition checking, I would like to refactor the expression of division into multiplication, for example:
Original version:
if(newValue / oldValue >= SOME_CONSTANT)
New version:
if(newValue >= oldValue *…
ocomfd
- 5,750
64
votes
1 answer
Treating a 1D data structure as 2D grid
I am working with a native class that represents a 2D image as a 1D array. If you want to change one pixel, for example, you need to now how to derive the index from the x,y coordinates.
So, let's say we have a 1D array array1d like this:
array1d =…
GladstoneKeep
- 2,669
61
votes
5 answers
Will a computer attempt to divide by zero?
We all know 0/0 is Undefined and returns an error if I were to put it into a calculator, and if I were to create a program (in C at least) the OS would terminate it when I try to divide by zero.
But what I've been wondering is if the computer even…
Ankush
- 851
59
votes
5 answers
get weighted random item
I have, for example, this table
+-----------------+
| fruit | weight |
+-----------------+
| apple | 4 |
| orange | 2 |
| lemon | 1 |
+-----------------+
I need to return a random fruit. But apple should be picked 4 times as…
fl00r
- 701
55
votes
14 answers
Why does DirectX use a left-handed coordinate system?
I considered posting on Stack Overflow, but the question strikes me as being far too subjective since I can't think of a reasonable technical explanation for Microsoft's choice in this matter. But this question has bugged me for so long and the…
greyfade
- 11,133
- 2
- 42
- 43
51
votes
11 answers
Is there a canonical book on mathematics for programmers?
I'm a self-taught programmer. I am honestly not good in math. What advice you can give to improve my Mathematical skills so that I will not be so insecure around my fellow programmers? What are the steps or guidelines that you can recommend to…
adietan63
- 735
- 1
- 7
- 9
40
votes
1 answer
Why was the caret used for XOR instead of exponentiation?
Not that it's really a problem for anyone that has faced this syntactic issue before, but I see a wild amount of confusion stemming from the use of the caret (^) as the XOR operation in lieu of the widely accepted mathematical exponentiation…
40
votes
12 answers
How to check if 4 points form a square?
Assume I have 4 points (they are 2-dimension), which are different from each other, and I want to know whether they form a square. How to do it? (let the process be as simple as possible.)
MarshalSHI
- 511
36
votes
4 answers
Prerequisite math skill for Introduction to Algorithms (CLRS) book
I already have knowledge about basic algorithms. Now I plan to study more advance algorithms and I decide to go with Introduction to Algorithms.
I'm not sure, do I need to refresh my math's skill before read this book or not? (I forget almost math…
Anonymous
- 2,049
36
votes
16 answers
Why use other number bases when programming
My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10.
I suggested that perhaps you could optimize longer equations by putting the variables in the correct…
JMD
- 530
35
votes
11 answers
Why do we still use floats?
I understand why floats served a purpose in the past. And I think I can see why they're useful in some simulation examples today. But I think those example are more exceptional than common. So I don't understand why floats are more prevalent in…
anon
32
votes
17 answers
Introducing Programming To a Mathematician
I currently am a programmer, I'm almost 16 years of age and have pretty much narrowed my careers down to something involving a Computer Science degree or Electrical Engineering degree (I know they are quite different but this question is about my…
ell
- 966