Why there is no STL for math in C++? And we should use <cmath>.
Why there is no STL for math in C++? And we should use <cmath>.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
I'm not sure I understand...
And we do use <cmath>
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
do you mean you want pre-built templates in the stl to do some math?Originally Posted by siavoshkc
There is not the slightest indication that [nuclear energy] will ever be obtainable. It would mean that the atom would have to be shattered at will.
-Albert Einstein, 1932
The reason the STL does not include math functions is probably that it wasn't viewed as particularly important. Support of mathematical functions was a bit of an after-thought in C, and this way of thinking carried across to C++ (although changes to the type system improved some things, such as not requiring float to be promoted to double in a lot of circumstances where C does that promotion).
IMHO, this has always been a weakness of both C and C++, and one of the reasons why I still use Fortran (which is a language designed for such things) for numerical work.
Ah, I got the question now. I was reading "And we should use <cmath>" as a suggestion, not as an affirmative. Sorry about that.
Math is not an objective of the programming language. C was not meant to be an answer to math problems. It is a general-purpose programming language. The standard library paradigm is what provides the "specialization" to solve specific problems (and of course the fact programmers can "extend" the language with their own libraries). This is not a weakness per-se of the language. It's just the way it was implemented. There's no keywords to the programming language past those provided strictly to guarantee the general-purpose theme of the language. In other words, it is left to the programmers to define the needed tools for their specific problems.
In fact the C standard library started out as a non-standard mesh of libraries defined by the C community at large to answer a few more common problems; IO, time, math, type definitions, string manipulation,...
C++ built on C, as you know, mainly to provide OOP and generic programming (to name the most influential). And yet the same generalistic purpose was kept. Libraries provide complex math. And there is really not much that can't be done in C++ by either using an already existing library (from the powerful like SciMath or MathLab to the more mainstream like Boost math libraries) or by coding our own with the existing C++ language keywords.
Last edited by Mario F.; 07-31-2006 at 07:23 AM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Take a look at this beautiful list:Let me ask my question this way. Why we should use C headers by a wrapper, instead of some headers with same (or even better) functionality written in C++ language?Code:<algorithm><bitset><cassert><cctype><cerrno> <cfloat><ciso646> <climits> <clocale><cmath><complex> <csetjmp><csignal><cstdarg> <cstddef><cstdio><cstdlib><cstring><ctime><cwchar><cwctype> <deque><exception><fstream><functional> <hash_map><hash_set> <iomanip><ios><iosfwd><iostream><iso646.h><istream><iterator> <limits><list><locale><map><memory><new><numeric><ostream> <queue><set><sstream><stack><stdexcept><streambuf> <string><strstream><utility><valarray><vector>
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
siavoshkc> Why we should use C headers by a wrapper, instead of some headers with same (or even better) functionality written in C++ language?
I honestly don't understand you're asking here.
MD> I asked Stroustrup about writing an operating system in std::c++, and he told me that there were some out there, but he also later basically admitted that c++ is not necessarity the best language for that job.
Ofcourse it isn't, since the std:: libraries are created to simplify low-level stuff... you need low level access for low level stuff (obviously), such as writing an OS.
What does this have to do with anything anyway?
No, you're asking it the wrong way. The right way is: Why should the C++ standard require the implementors to reimplement something that works perfectly fine the way it is, i.e. the C way?Originally Posted by siavoshkc
C++ provides std::complex, something that is missing from C (or was until C99). It provides std::valarray, which is a data structure optimized for heavy number crunching, something that is also missing from C. But all those simple mathematic functions that have nothing object-oriented about them, it simply took them from C, because they were available. What's wrong with that?
Most other C headers taken into C++ are there just because someone might want to migrate C code to C++ and have the C functions in the std namespace.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I'd really like to see that admission. I don't think I've ever read Stroustrup admit that C++ wasn't the best tool for anything.Originally Posted by MDofRockyView
Not really. Obviously iostream libraries are pretty much out, but there's no reason you couldn't use C++ (including std headers) to write an OS. Although you'd probably have to implement the C run time first....Originally Posted by Osaou
as for STL math, there are the types CornedBee mentioned, and if you'd read what MDofRockyView wrote earlier, you'd know that boost has several math classes including an entire math sub library and the boost graph library.
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Boost seems to be a good package. Its libraries are trustable, aren't they?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Absolutely. Some of them have even been admited for the next standard, hopefully soon to come.
Last edited by Mario F.; 08-01-2006 at 07:05 AM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.