How much maths do I need for C++?

As the heading states, what are the crucial maths concepts I have to learn and perfect if I want to go into Video Game Programming. I'm above average in Maths for all my life, nothing to excellent. I'm 14 and I would like some guidance so I know which direction to go.

Thanks.
closed account (EwCjE3v7)
+, -, *, /

Thats about it :).
:D I'm pretty sure your correct but say if I were to go into deep complicated C++. I heard you have to be pretty great in Maths to achieve that.
closed account (EwCjE3v7)
A great maths background isn't required, sure it may help you. if you go to school, that book can teach you a few tricks and I don't really know of any maths books that would be really helpful so if you want a book on maths, I'm sure someone else here knows of a great one.

So you don't have to be great at maths, just need to know the above and your set.
Last edited on
C++ is a tool. Like a hammer. You do not need to study architecture to hammer a nail. But if you want to build a brigge, you will need specific knowledge. Though if you have it is is more likely that you will order people who only knows how to swing a hammer instead of working yourself.

So you do not need to know math to use C++. But you might need to know math to solve problems with C++.
I'm pretty sure your correct but say if I were to go into deep complicated C++. I heard you have to be pretty great in Maths to achieve that.

C++ is just a language. You don't need much math at all to be good in the language. To be good in programming in general, it helps to have skills in formal logic and discrete math.

There are a lot of things you can do with the language that require a lot of math.

Game development might be sort of math heavy, but not that bad for the most part ( Linear Algebra mostly ). Machine learning and artificial intelligence are extremely math heavy ( linear algebra, statistics, calculus, differential equations ), also scientific computing.

For anything visual, take a look at linear algebra. Specifically regarding rotational matrices and vector math. That will help you understand how to move points in relation to other points.
@ OP: Order of Operations, I can not stress enough how important this concept is to learning how to program. I say concept because you need to be ready to expand this idea beyond "My Dear Aunt Sally...".

It helps in programming to be mathematically inclined because that is a subject that you study early on which is detail oriented. A lot of the problems may appear to be the same at first glance but due to some key point they are handled completely differently. It also starts to introduce critical concepts that are harder to find else where like the scope of a variable.

Other then that the rest of the math is pretty simple. For instance if you understand what is wrong with fitting 50 characters into a container where you only made room for 2, and you can remember to add 1 to account for the necessary null terminator, then you're off to a good start.
Phew, thanks guys. I was really starting to doubt myself.

I'm currently in the 8th grade and all the algebra we have done so far seems pretty easy, but I guess that's because it's basic algebra.

Thank you everyone! It's been a great help!
If you want to make a game you will need a lot of math and physics knowledge (unless it is a very simple game). Other than that, the amount of math you use depends entirely on how mathy he problem you're trying to solve is.
Wow, why is nobody talking about: %

I love this operation. I use it all the time for really neat stuff.

Counter increasing with easy wrap-around (0..255)?
cnt = ++cnt % 256;

Limit the randomizer range (1..100)?
int r = rand() % 100 + 1;

Separating tens and ones of an integer?
1
2
draw_digit(GetHour() / 10);	// tens
draw_digit(GetHour() % 10);	// ones 


Even/Odd test?
if(x % 2 == 0) and if(x % 2 == 1)

Although, this works nice too:
if((x & 1) == 0) and if((x & 1) == 1)

Not sure which one compiles to the better machine code.
Last edited on
We aren't talking about it much because it's not actually as useful as you make it out to be.

Using % with ever increment of a value is more expensive (less efficient) than just using an if statement to check if the value is above the max and resetting it.

rand() is deprecated and instead the C++11 random number generates return a floating point value in the range [0.0, 1.0) so you just multiply to get the range you want.

Base conversion is actually a place where it still sees use, but it's not something you do very often.

The even/odd test is debatable - some people insist on using &1 to check the LSB, but this is probably what the compiler converts the code to anyway when you write %2, so it depends on your compiler optimizations. Even so, you don't really need to test for even or odd very often...
Using % with ever increment of a value is more expensive (less efficient) than just using an if statement to check if the value is above the max and resetting it.
It is actually not. Even without optimisations you have a great chance to have more efficient code than branching. With optimisations turned on these compiles in same code.

rand() is deprecated
Sadly it is still not deprecated. Waiting for C++1z. Main problem with using modulus is that resulting distribution is not uniform.

Problem with (x % 2) == 1 is that it might not work on negative numbers. !(x % 2 == 0) usually works fine.
@MiiNiPaa: Ah, so it's counter-intuitive. I am interested to know why, at the hardware level, modulus is faster than branch prediction.

As for rand, I thought it was deprecated, but I guess it is just discouraged (which, I suppose, is unofficial deprecation).
Back to the main topic...from what I've seen most programs don't require you to use more than the basic + - * /, as said in the first answer, but you should know boolean algebra since you'll use it a lot for conditions and in case you work with bits (1's and 0's in your variables).

Apart from that you should pay attention on math class when they start going over vectors because you might need some of those formulas when you start working in graphical environment.

There are also algorithms, to understand them you'll need to understand graph theory and abstract math stuff. It's complicated, you'll probably learn this stuff in math class when you go to university.

Everything in math except this is only used if the specific task requires you to, which isn't going to be very often and usually you can just google for the formulas you need.
It depends on hardware mostly. Branch prediction is not guaranteed to happen for example. Modulus is a single instruction on some CPU (ARM for example).
Also at least on GCC wraparound code was optimized to single instruction "zero-extend least significand 8 bits from this register" (or to single and instruction for other powers of 2) on O1, when conditional way was only optimized on Os. On O3 conditional way still had comparsion here which cost might become neglible if branch prediction will work.
Conditional becomes potentionally faster if you need wraparoung not by power of 2 though.

I do not think this will make any difference though. Because if your program have a bottleneck in wraparound code, it is least of your problems.
Ah, I didn't realize were were talking powers of 2.
Topic archived. No new replies allowed.