   Is C better for math ?
  Hey,I'm going to write the math library of my engine.I studied the source code published in the Doom 3 SDK and the HL2 one.I discovered that Doom 3 Math part is coded using classes while the HL2 lib was done using C only.What do you think ?Is C better ( for performance ) than C++ for the math part of an engine ?I think that VC++ should work better with classes, but I don't know how to program my lib.Thanks, Bye =)   
  C does not and has not outperformed C++ for some years now -- assuming you know what you are doing. When it comes to doing math in C++, implementing some of the operators is tricky to do completely correctly such that excessive intermediate copies are not created, which can be a bit of a mess.   ;  Hey, Thanks for the answer. Really i've already written some classes in C++ but i'm thinking about re-writing all in C. So, do you think C would be faster ? ( even in VC++ ? )   ;  C99 in theory can perform better than C++ in a limited set of cases because of the inclusion of restrict pointers which allow for more aggressive optimizations in dealing with pointer aliasing. However, if you are using Visual C++, then there is no real gain in using C since MSVC doesn't support the C99 specification.   ;Quote:Original post by SiCraneC99 in theory can perform better than C++ in a limited set of cases because of the inclusion of restrict pointers which allow for more aggressive optimizations in dealing with pointer aliasing. However, if you are using Visual C++, then there is no real gain in using C since MSVC doesn't support the C99 specification.Not to mention VC supports __restrict, so you can simply drop it behind a compiler version dependent #define.   ;  There's no advantage to either performance wise (unless you really are going to be using restrict pointers).C++ does however offer mathematical operator overloading and namespaces which are niceties.If the rest of your engine is written in C++ then you might as well stay consistent.   ;  A decent implementation of a math library is D3DXMath and I doubt that you can do a better job. So if you work on the PC I recommend using this instead of rolling your own...;Quote:Original post by dmatterC++ does however offer mathematical operator overloading and namespaces which are niceties.Let's not forget C++ templates. Nobody wants to overload their functions for so many different numerical types.But I agree with Donnie. If it's feasible, you can save yourself a lot of time and effort by using D3DX. I use it on a daily basis; it has never let me down and still occasionally impresses me.Admiral   ;  Not to mention general processor libraries like uBLAS (or Blitz++), POOMA etc. that are claimed to match and bypass even the highly optimised Fortran (and also C) libraries due to heavy and aggressive use of template enabled optimisations.There are, though, also libraries like D3DXMath and other GPGPU stuff floating around that is brutally efficient in SIMD/MIMD computations.   ;Quote:Original post by DonDickieDA decent implementation of a math library is D3DXMath and I doubt that you can do a better job. So if you work on the PC I recommend using this instead of rolling your own...Computers running OS X, Unix and Linux are often PCs as well. I believe that you mean if the OP is running Windows.   