Top "Math" questions

Math involves the manipulation of numbers within a program.

What is the best way to get all the divisors of a number?

Here's the very dumb way: def divisorGenerator(n): for i in xrange(1,n/2+1): if n%i == 0: yield i yield n …

python algorithm math
Circle line-segment collision detection algorithm?

I have a line from A to B and a circle positioned at C with the radius R. What is …

algorithm math line collision-detection geometry
Javascript: formatting a rounded number to N decimals

in JavaScript, the typical way to round a number to N decimal places is something like: function roundNumber(num, dec) { …

javascript math rounding decimal-point
Least common multiple for 3 or more numbers

How do you calculate the least common multiple of multiple numbers? So far I've only been able to calculate it …

algorithm math lcm
Generate a random point within a circle (uniformly)

I need to generate a uniformly random point within a circle of radius R. I realize that by just picking …

math random geometry probability
How to calculate modulus of large numbers?

How to calculate modulus of 5^55 modulus 221 without much use of calculator? I guess there are some simple principles in number …

math modulo
How to find GCD, LCM on a set of numbers

What would be the easiest way to calculate Greatest Common Divisor and Least Common Multiple on a set of numbers? …

java math greatest-common-divisor lcm
Javascript (+) sign concatenates instead of giving sum of variables

Why when I use this: (assuming i = 1) divID = "question-" + i+1; I get question-11 and not question-2?

javascript math
Difference between Math.Floor() and Math.Truncate()

What is the difference between Math.Floor() and Math.Truncate() in .NET?

.net math
How to get whole and decimal part of a number?

Given, say, 1.25 - how do I get "1" and ."25" parts of this number? I need to check if the decimal part …

php math