Math operators
Math operators in C with µnit
Basic Operators
All the same operators you'd expect exist in C:
x + y;
x - y;
x * y;
x / y;
If you're coming from Python, +=, -=, *=, /= are all the same.
Postfix and Prefix Operators
In addition, there are also the ++ and -- operators:
x++; // += 1
x--; // -= 1
The name of C++ is a bit of a joke by the creator, it's meant to be "incremented C" or "better C".
These increment (++) and decrement (--) operators can be used in two forms: postfix and prefix.
Postfix (x++ or x--): The value of x is used in the expression first, and then x is incremented or decremented. For example:
int a = 5;
int b = a++; // b is assigned 5, then a becomes 6
Prefix (++x or --x): x is incremented or decremented first, and then the new value of x is used in the expression. For example:
int a = 5;
int b = ++a; // a becomes 6, then b is assigned 6
I generally avoid prefix operators. If I want to increment a variable but keep the original value, I do that in two steps. Postfix is more common, especially in loops, which we'll get to.
Write some code
Snek its "project score" that's dependent on how maintainable and "high quality" their codebase is. The larger the score, the harder it is to work in the project. The score is calculated as follows:
- Multiply the number of files by the number of commits to get the size factor.
- Add the size factor to the number of contributors to get the complexity factor.
- Multiply the complexity factor by the average bug criticality (a number between 0 and 1) to get the final score.
float snek_score(
int num_files,
int num_contributors,
int num_commits,
float avg_bug_criticality
);