Would it be worth inlineing these functions?

Just out of curiosity ( I normally stay away from inline functions ) - But would it be worth making these functions inlined - or would it do no good or no change?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "MA_Core.h"

#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>

// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
float maDegreesToRadians(float degree)
{
	return degree * ((float)M_PI / 180.0f);
}

// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
float maRadiansToDegrees(float radians)
{
	return radians * (180.0f / (float)M_PI);
}

// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
float maRandomFloat(float min, float max)
{
	float r = (float)rand() / (float)RAND_MAX;
	return min + r * (max - min);
}

// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
bool maEqualsTolerance(float lhs, float rhs, float tolerance)
{
	return fabsf(lhs - rhs) < tolerance;
}


Cheers,
Myth.
Remember that inline is interpreted by the compiler as merely a suggestion to inline, rather than an order. Such short functions are usually better inlined. Specially if they're calling from inside a loop.
Personally, I never write functions so short. If I need something like that, I write a macro. But then, I'm one of those hybrid C-C++ programmers.
Mythios, The only way to know for sure is to benchmark the programs that use these functions. In general, I would guess that inlining would speed things up in the general case, except for maybe maRandomFloat() because of the call to rand(). But as helios said, the compiler will figure that out for you.

And ignore helios's comment on macros and function size. Don't use macros in C++. You loose all type safety and end up with unintended side effects that are virtually impossible to track down. These are perfect the way they are. Besides -- maximum function length is the only function size limit that matters.
Thanks guys - that helped :)
Topic archived. No new replies allowed.