Skip to main content

Questions tagged [math]

For questions about designing and implementing mathematical functions or operations in a programming language.

Filter by
Sorted by
Tagged with
7 votes
0 answers
154 views

How to usefully implement trig (and other irrational functions) on rational primitives

Based on my limited experience, most languages that have rationals as their primary number type simply do not have built-ins for sin,...
5 votes
6 answers
705 views

What programming languages contain a built-in imaginary data type?

Many languages like R, Julia, and Python store imaginary numbers as a complex number with a 0 valued real component. We may see this with the following R code: ...
7 votes
1 answer
415 views

Why is truncated or non-Euclidean division/modulo the norm?

Related to, but not the same question: Distinguishing modulo (Euclidean division) from remainder There are multiple ways a modulo operation can be performed. Most implementations, in C, for example, ...
5 votes
9 answers
2k views

Correctness of mixed signed/unsigned arithmetic

I'm implementing signed and unsigned integers in my language. They are represented in C as signed long and unsigned long ...
31 votes
11 answers
19k views

Why do so many programming languages not have a "built-in" way to do simple math functions?

Note 1: My question is not about the factorial function. It's about "simple math functions" that high-school level pocket calculators can do, but most programming languages cannot do without ...
20 votes
5 answers
4k views

Is there any particular reason to only include 3 out of the 6 trigonometry functions?

Most languages seem to only have sin cos and tan. While the other 3 are just ...
20 votes
4 answers
5k views

What obstacles prevented C and C++ from standardizing π?

C does not even have M_PI standardized. C++ only added std::numbers::pi very recently. Yes, the fact that this took so long does ...
10 votes
2 answers
558 views

Can you represent a language with a group with a small/simple generator set?

I'm wondering whether its possible to construct a group where the elements are all possible valid programs, with a small or simple generator set. That way you could have a series of operations you can ...
19 votes
3 answers
4k views

Why does MATLAB have left division/solve?

In MATLAB (and Octave), the \ (or mldivide) and \. operators are provided with the exact ...
9 votes
6 answers
3k views

What syntax could be used to implement both an exponentiation operator and XOR?

C does not have an exponentiation operator, so that freestanding implementations that lack the math libraries could lack exponentiation as a whole, and still be permissible by the C standard. As a ...
13 votes
5 answers
786 views

Distinguishing modulo (Euclidean division) from remainder

The % operator in most programming language provide a remainder from integer division. When both operands are positive all works as expected. But when the number is ...
6 votes
2 answers
375 views

Are there any disadvangates to requiring sincos() type functions?

sincos() is just a way to compute sin() and cos() at once, possibly at improved performance ...