Questions tagged [math]

Math involves the manipulation of numbers within a program. For general math questions, please ask on math.stackexchange.com. Note: If your question is about unexpected results in floating point calculations, please read https://stackoverflow.com/questions/588004/is-floating-point-math-broken first.

Mathematics is the study of quantity, structure, space, and change. Mathematicians seek out patterns, formulate new conjectures, and establish truth by rigorous deduction from appropriately chosen axioms and definitions.

Through the use of abstraction and logical reasoning, mathematics evolved from counting, calculation, measurement, and the systematic study of the shapes and motions of physical objects. Practical mathematics has been a human activity for as far back as written records exist.

Mathematics is behind all programming at some level, but math questions here should be specifically related to a programmed implementation. General math questions can be asked at Mathematics. Research level mathematics questions can be asked at MathOverflow.

Notable questions that may be dupe targets. Check these questions before asking again!

43708 questions
15
votes
1 answer

What's the difference between "pi" and "M_PI" in objc

Including some math in my code I stumbled over the constant "PI". At least in my Xcode version 4.6 I could use either one. But what is the difference between pi and M_PI? The documentation is little bit tight on that topic.
JFS
  • 2,992
  • 3
  • 37
  • 48
15
votes
4 answers

Find the normal angle of the face of a triangle in 3D, given the co-ordinates of its vertices

As you may be able to tell from this screenshot, I am trying to make a physics engine for a platformer I am working on, but I have run into a definite problem: I need to be able to find out the angle of any one of the triangles that you can see make…
Chris
15
votes
9 answers

How do programming languages handle huge number arithmetic

For a computer working with a 64 bit processor, the largest number that it can handle would be 264 = 18,446,744,073,709,551,616. How does programming languages, say Java or be it C, C++ handle arithmetic of numbers higher than this value. Any…
Ajay
  • 7,378
  • 18
  • 57
  • 75
15
votes
3 answers

Select sum where clause SQL

I have the following code, it works but I am trying to separate SUM for each Banksphere.servicio_id column, this code SUM only one servicio_id... I'm a bit lost, can someone help me? As you can see, every WHERE clause is exactly the same but…
Robert W. Hunter
  • 2,895
  • 7
  • 35
  • 73
15
votes
8 answers

How to Solve Equations with java?

I have three equations like the following ones: x + y + z = 100; x + y - z = 50; x - y - z = 10; How can I find the values of x, y, and z with Java? String equation1="x+y+z=100;"; String equation2="x+y-z=50;"; String equation3="x-y-z=10;"; int[]…
Cong De Peng
  • 321
  • 1
  • 4
  • 11
15
votes
4 answers

I need faster floating point math for .NET C# (for multiplying and dividing big arrays)

I need fastest possible way to multiply and divide big arrays of data. I've read this (wrote by Ben Voigt here): .NET doesn't use MMX or SSE or AVX, as of the current version (...) modern C++ compilers not only allow SIMD usage, but can…
Kamil
  • 13,363
  • 24
  • 88
  • 183
15
votes
3 answers

How to determine if a vector is between two other vectors?

I am looking for a fast and effective way to determine if vector B is Between the small angle of vector A and vector C. Normally I would use the perpendicular dot product to determine which sides of each line B lies on but in this case is not so…
user1759679
  • 193
  • 1
  • 1
  • 6
15
votes
7 answers

Compute fast log base 2 ceiling in python

for given x < 10^15, quickly and accurately determine the maximum integer p such that 2^p <= x Here are some things I've tried: First I tried this but it's not accurate for large numbers: >>> from math import log >>> x = 2**3 >>> x 8 >>> p =…
Rusty Rob
  • 16,489
  • 8
  • 100
  • 116
15
votes
2 answers

Extracting View Frustum Planes (Gribb & Hartmann method)

I have been grappling with the Gribb/Hartmann method of extracting the Frustum planes for some time now, with little success. I want to build a camera view-frustum to cull my scene. I am working with column-major matrices in a right-handed…
DAVco
  • 325
  • 2
  • 3
  • 10
15
votes
3 answers

Computing padding required for n-byte alignment

Say I have a collection of data (eg: strings) that must be stored in a binary file padded so that each string is, say, 4-byte aligned. So if I have a string of length 11, it would get padded to 12 (with null bytes). If I have a string of length 24,…
MxLDevs
  • 19,048
  • 36
  • 123
  • 194
15
votes
5 answers

Three egg proble​m

I was just reading The Two Egg Problem: The Two Egg Problem You are given two eggs, and access to a 100-storey building. Both eggs are identical. The aim is to find out the highest floor from which an egg will not break when dropped out of a window…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
15
votes
4 answers

Most efficient way to find distance between two circles in java?

So apparently calculating square roots is not very efficient, which leaves me wondering what the best way is to find out the distance (which I've called range below) between two circles is? So normally I would work out: a^2 + b^2 = c^2 dy^2 + dx^2…
kiman
  • 359
  • 5
  • 13
15
votes
4 answers

Haskell: Between a list and a tuple

I want a function +++ that adds two mathematical vectors. I could implement vectors as [x, y, z] and use: (+++) :: (Num a) => [a] -> [a] -> [a] (+++) = zipWith (+) And thus accomodate any n-dimensional vector (so this would work for [x, y] too). Or…
mk12
  • 25,873
  • 32
  • 98
  • 137
15
votes
3 answers

How do you get the next value in the floating-point sequence?

Does Python provide a function to get the floating-point value that results from incrementing the least significant bit of an existing floating-point value? I'm looking for something similar to the std::nextafter function that was added in C++11.
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
15
votes
7 answers

Rounding numbers in Sass and adjusting the amount of decimals

Is their a way in sass to change the digit that rounding occurs on, I would like to stop rounding of a number like this 2.0242914979757085% to this 2.024%. I would like to adjust the amount of decimals in the output css
Lawrence
  • 837
  • 3
  • 12
  • 26
1 2 3
99
100