Tag: math

62 votes
11 answers
1.3K views
Fast ceiling of an integer division in C / C++

Given integer values x and y, C and C++ both return as the quotient q = x/y the floor of the floating point eq

avatar
Patsy
0 1 0 9
asked 07 September, 2021
57 votes
7 answers
2.5K views
How can I divide two integers to get a double?

How do I divide two integers to get a double?

avatar
Santiago
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
804 views
Convert a number range to another range, maintaining ratio

I'm trying to convert one range of numbers to another, maintaining ratio. Maths is not my strong point.

avatar
Shanita
0 1 0 9
asked 07 September, 2021
69 votes
7 answers
2.5K views
What is "entropy and information gain"?

I am reading this book (NLTK) and it is confusing. Entropy is defined as: Entropy is the sum of the proba

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
55 votes
25 answers
2.4K views
How to evaluate a math expression given in string form?

I'm trying to write a Java routine to evaluate math expressions from String values like: "5+3" "10-40" "(

avatar
Stacia
0 1 0 9
asked 07 September, 2021
66 votes
16 answers
2K views
How to round up the result of integer division?

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Jav

avatar
Hilario
0 1 0 9
asked 07 September, 2021
67 votes
30 answers
1.2K 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

avatar
Alba
0 1 0 9
asked 07 September, 2021
58 votes
7 answers
1.9K views
Fastest way to determine if an integer is between two integers (inclusive) with known sets of values

Is there a faster way than x >= start && x <= end in C or C++ to test if an integer is between t

avatar
Stacia
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
3K views
Calculate distance between 2 GPS coordinates

How do I calculate distance between two GPS coordinates (using latitude and longitude)?

avatar
Stacia
0 1 0 9
asked 07 September, 2021
59 votes
10 answers
1.6K views
What is the standard way to add N seconds to datetime.time in Python?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so t

avatar
Janella
0 1 0 9
asked 07 September, 2021
51 votes
21 answers
732 views
Is there a standard sign function (signum, sgn) in C/C++?

I want a function that returns -1 for negative numbers and +1 for positive numbers. http://en.wikipedia.org/wi

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
56 votes
13 answers
734 views
Difference between Math.Floor() and Math.Truncate()

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

avatar
Shanita
0 1 0 9
asked 07 September, 2021
62 votes
12 answers
2.4K views
JavaScript math, round to two decimal places

I have the following JavaScript syntax: var discount = Math.round(100 - (price / listprice) * 100)

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
66 votes
16 answers
2.8K views
What is the difference between &apos;/&apos; and &apos;//&apos; when used for division?

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results: >&

avatar
Thurman
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
1.9K views
How to sum array of numbers in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
63 votes
26 answers
2.7K views
How to check if a number is a power of 2

Today I needed a simple algorithm for checking if a number is a power of 2. The algorithm needs to be: Simpl

avatar
Majorie
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
791 views
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 unsig

avatar
Bryant
0 1 0 9
asked 07 September, 2021
57 votes
6 answers
2.2K views
How do I determine whether my calculation of pi is accurate?

I was trying various methods to implement a program that gives the digits of pi sequentially. I tried the Tayl

avatar
Hilario
0 1 0 9
asked 07 September, 2021
61 votes
28 answers
1.6K views
Understanding "randomness"

I can't get my head around this, which is more random? rand() OR: rand() * rand() I´m finding it a

avatar
Thurman
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.2K views
Designing function f(f(n)) == -n

A question I got on my last interview: Design a function f, such that: f(f(n)) == -n Where n is a 3

avatar
Alphonso
0 1 0 9
asked 07 September, 2021