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 calling a library (square roots, logarithms, trigonometric functions, factorials, etc.).
Note 2: Comments and answers have said things like "by providing a factorial out-of-the-box you'd deprive CS teachers of their favorite recursive-programming example". While I agree that this joke is clever, it's unlikely that the developers of Java intentionally didn't include a factorial function so that CS teachers could have something to teach, so this isn't the type of answer I'm seeking.
Preamble
I understand that not all programming languages can be like MATLAB, which by default allow users to write factorial(10)
for 10!, sqrt(10)
and for $\sqrt{10}$. Indeed, MATLAB, Mathematica, Maple, and other similar platforms, take up considerably more hard drive space than most compilers, even when combined with the space taken up by a typical heavy-weight IDE.
However, even some of the least sophisticated calculators have a button for these simple functions.
Why would so many languages like Java and C++ (see this StackOverflow thread if interested) not have a built-in way (i.e. without using a library) to do the basic math that simple calculators can do?
Related questions based on prior research:
- Is there any particular reason to only include 3 out of the 6 trigonometry functions? (but the answers to that do not answer the question here).
- Why programming languages does not have factorial function? (the answers say that such functions are not used much, that they would be considered "bloat", and that language designers want to avoid putting a flag in the ground that says "this is how it's done"; however my opinion is that these functions are common enough to be included in pocket calculators which have fewer KB of RAM than a computer, so they are not much "bloat", and if there's already a flag in the ground for multiplication and exponentiation I don't see why there can't be one for
sin()
or factorials).