The Point Defined

In the world of game programming, you will deal with many different types of functions. In general, a function is a rule that takes in information (input) and returns new information (output). In programming, you can write functions that take in various types of input, such as variables, text, or numbers, and return a different type of information or even perform an action as output. In a well-written program, you should compartmentalize repeatable tasks in functions so that the code is kept simple and clean. Let's take a look at an example of a well-commented and useful function:

 // purpose: determine whether a number is a power of 2 // input: the number being checked // output: true if it's a power of 2, else false bool powOfTwo(int ...

Get Beginning Math and Physics for Game Programmers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.