# All Questions

**1970**

votes

**22**answers

197340 views

### Is floating point math broken?

0.1 + 0.2 == 0.3
-> false
0.1 + 0.2
-> 0.30000000000000004
Why does this happen?

**737**

votes

**19**answers

368925 views

### What is JavaScript's highest integer value that a number can go to without losing precision?

Is this defined by the language? Is there a defined maximum? Is it different in different browsers?

**238**

votes

**26**answers

288222 views

### Evaluating a math expression given in string form

I'm trying to write a Java routine to evaluate simple math expressions from String values like:
"5+3"
"10-40"
"10*3"
I want to avoid a lot of if-then-else statements.
How can I do this?

**902**

votes

**32**answers

270356 views

### Determine Whether Two Date Ranges Overlap

Given two date ranges, what is the simplest or most efficient way to determine whether the two date ranges overlap?
As an example, suppose we have ranges denoted by DateTime variables StartDate1 to E...

**70**

votes

**7**answers

127866 views

### Division of integers in Java

This is a basic question but I can't find an answer. I've looked into floating point arithmetic and a few other topics but nothing has seemed to address this. I'm sure I just have the wrong terminol...

**640**

votes

**33**answers

516846 views

### Calculate distance between two latitude-longitude points? (Haversine formula)

How do I calculate the distance between two points specified by latitude and longitude?
For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to underst...

**289**

votes

**30**answers

143242 views

### Fastest way to list all primes below N

This is the best algorithm I could come up.
def get_primes(n):
numbers = set(range(n, 1, -1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers...

**12**

votes

**1**answers

2797 views

### How do I compose a rotation matrix with human readable angles from scratch?

The one thing that has always hindered me from doing 3D programming is failing to understand how math works. I can go along with math fine in programming flow using methods and functions, then its all...

**249**

votes

**20**answers

76884 views

### Why can't decimal numbers be represented exactly in binary?

There have been several questions posted to SO about floating-point representation. For example, the decimal number 0.1 doesn't have an exact binary representation, so it's dangerous to use the == ope...

**131**

votes

**5**answers

223696 views

### What is the behavior of integer division?

For example,
int result;
result = 125/100;
or
result = 43/100;
Will result always be the floor of the division? What is the defined behavior?