File: rtmath.h

package info (click to toggle)
robotour 3.1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,596 kB
  • ctags: 2,972
  • sloc: cpp: 17,705; sh: 3,060; ansic: 2,778; makefile: 144
file content (98 lines) | stat: -rwxr-xr-x 3,091 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * rtmath.h
 * 
 * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
 * and Martin Trautmann (martintrautmann@gmx.de) 
 * 
 * This file may be distributed and/or modified under the terms of the 
 * GNU General Public License version 2 as published by the Free Software 
 * Foundation. 
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

/** \file
  * Contains the class Math, which provides static helper functions
  * and mathematical constants.
  * @see Math
  */

#ifndef __LRT_MATH__
#define __LRT_MATH__

namespace lrt {

/** Class Math provides some static helper functions to compute often-used mathematical functions
  * in a system-independent manner.
  * Currently under construction.
  */
class Math  
{
public:
	/** The largest positive value which is representable as a 32-bit integer. */
	static const int MAX_INT;
	/** The largest negative value which is representable as a 32-bit integer. */
	static const int MIN_INT;

	/** The most possibly exact representation of the number Pi. */
	static const double PI;
	/** The most possibly exact representation of the number <b>e</b> (the
	  * base of the natural logarithm). */
	static const double E;

	
	/** Returns the bigger one of the given integers. 
	  * Note: This function is inline and will be translated into the usual code.
	  * So please use it to enhance code readability. */
	static inline int max(int num1, int num2);
	/** Returns the smaller one of the given integers. 
	  * Note: This function is inline and will be translated into the usual code.
	  * So please use it to enhance code readability. */
	static inline int min(int num1, int num2);
	/** Returns the absolute value of the given integer. 
	  * Note: This function is inline and will be translated into the usual code.
	  * So please use it to enhance code readability. */
	static inline int abs(int num);

	/** Creates a pseudorandom number between (and including) the values <tt>from</tt>
	  * and <tt>to</tt>.<br>
	  * If you do not use seed() or randomize() before using rand(), it will
	  * initialize itself to return randomized numbers.
	  */
	static int rand(int from, int to);

	/** Creates reproducable pseudorandom numbers by seeding the random number
	  * generator with a fix number. 
	  */
	static void seed(unsigned long seed);

	/** Creates unreproducable, but "really random" numbers by seeding the random
	  * number generator with a number from a random source (usually the system timer).
	  */
	static void randomize();


	/// Computes the square root of num. 
	static double sqrt(double num);
	static double log10(double num);
	static double ln(double num);
	static double exp(double num);
	static double sin(double num);
	static double cos(double num);
	static double tan(double num);

private:
	static bool randomInit;
	Math();
	~Math();
};

} // namespace


#include "rtmath.inline.cpp"

#endif