source: trunk/src/lol/math/math.h @ 1888

Last change on this file since 1888 was 1888, checked in by lolbot, 8 years ago

fixed 23 files out of 277:

  • fixed 1270 CR characters
  • fixed 56 trailing spaces
  • fixed 5085 tabs
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// Various maths functions
13// -----------------------
14//
15
16#if !defined __LOL_MATH_MATH_H__
17#define __LOL_MATH_MATH_H__
18
19#include <cmath>
20#include <cstdio>
21#include <stdint.h>
22
23namespace lol
24{
25
26/* Standard cmath functions */
27static inline double sqrt(double const &x) { return std::sqrt(x); }
28static inline float sqrt(float const &x) { return std::sqrt(x); }
29
30static inline double sin(double const &x) { return std::sin(x); }
31static inline double cos(double const &x) { return std::cos(x); }
32static inline double tan(double const &x) { return std::tan(x); }
33static inline float sin(float const &x) { return std::sin(x); }
34static inline float cos(float const &x) { return std::cos(x); }
35static inline float tan(float const &x) { return std::tan(x); }
36
37static inline double asin(double const &x) { return std::asin(x); }
38static inline double acos(double const &x) { return std::acos(x); }
39static inline double atan(double const &x) { return std::atan(x); }
40static inline float asin(float const &x) { return std::asin(x); }
41static inline float acos(float const &x) { return std::acos(x); }
42static inline float atan(float const &x) { return std::atan(x); }
43
44static inline double atan2(double const &y, double const &x)
45{
46    return std::atan2(y, x);
47}
48
49static inline float atan2(float const &y, float const &x)
50{
51    return std::atan2(y, x);
52}
53
54/* Our extensions */
55static inline void sincos(double const &x, double *s, double *c)
56{
57    *s = std::sin(x);
58    *c = std::cos(x);
59}
60
61static inline void sincos(float const &x, float *s, float *c)
62{
63    *s = std::sin(x);
64    *c = std::cos(x);
65}
66
67static inline double lerp(double const &a, double const &b, double const &x)
68{
69    return a + (b - a) * x;
70}
71static inline float lerp(float const &a, float const &b, float const &x)
72{
73    return a + (b - a) * x;
74}
75
76
77/* These accelerated functions will be merged into the above, one day */
78double lol_sin(double);
79double lol_cos(double);
80double lol_tan(double);
81void lol_sincos(double, double*, double*);
82void lol_sincos(float, float*, float*);
83double lol_asin(double);
84double lol_acos(double);
85double lol_atan(double);
86double lol_atan2(double, double);
87
88} /* namespace lol */
89
90#endif // __LOL_MATH_MATH_H__
91
Note: See TracBrowser for help on using the repository browser.