1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #ifndef _NONSTD_MATH_H_ |
---|
6 | #define _NONSTD_MATH_H_ |
---|
7 | |
---|
8 | |
---|
9 | #ifdef _MSC_VER |
---|
10 | #define _USE_MATH_DEFINES //after this is defined, the next #include <math.h> or <cmath> will define M_PI etc. |
---|
11 | #include <math.h> //w vc2008 dzia³a³o tu <cmath>, ale w vc2010 juz nie bo "co" (jaki inny .h stl'a?) includuje wczeniej <cmath> bez _USE_MATH_DEFINES, a <cmath> includuje <math.h> (ale tylko raz bo ma "include guards" jak kazdy .h) |
---|
12 | #include <float.h> |
---|
13 | //#define isnan(x) _isnan(x) //since 2014 we use std::isnan() |
---|
14 | #define finite(x) _finite(x) |
---|
15 | #else //m.in. __BORLANDC__ |
---|
16 | #include <math.h> |
---|
17 | #endif |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | //random number generator: |
---|
22 | #include "random.h" |
---|
23 | RandomGenerator &rndGetInstance(); |
---|
24 | |
---|
25 | inline double rndDouble(double limit_exclusive) { return rndGetInstance().getDouble() * limit_exclusive; } |
---|
26 | inline unsigned int rndUint(unsigned int limit_exclusive) { return (unsigned int)(rndGetInstance().getDouble() * limit_exclusive); } //returns random from 0..limit_exclusive-1 |
---|
27 | inline void rndSetSeed(unsigned int seed) { rndGetInstance().setSeed(seed); } |
---|
28 | inline unsigned int rndRandomizeSeed() { return rndGetInstance().randomize(); } |
---|
29 | |
---|
30 | //floating point specific numbers |
---|
31 | #include "stdlib.h" |
---|
32 | |
---|
33 | #ifdef __BORLANDC__ |
---|
34 | #include <float.h> |
---|
35 | #define isnan(x) _isnan(x) //http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c |
---|
36 | #define finite(x) _finite(x) |
---|
37 | #endif |
---|
38 | |
---|
39 | #ifdef LINUX |
---|
40 | #define _isnan(a) isnan(a) |
---|
41 | #endif |
---|
42 | |
---|
43 | #ifdef IPHONE |
---|
44 | #define finite(x) (!isinf(x)) |
---|
45 | #define _isnan(a) isnan(a) |
---|
46 | #endif |
---|
47 | |
---|
48 | |
---|
49 | #if defined SHP |
---|
50 | //#define __assert_func(a,b,c,d) 0 //Currently, we are sorry to inform you that assert() is not yet supported. We have considered your request for internal discussion. Na szczêcie jest w³asna (byle by by³a, bo i tak zak³adamy ze assert ktore przeciez dziala tylko w trybie debug nie jest potrzebne na bada) implementacja w "bada-assert.cpp" |
---|
51 | #define isnan(x) false //isnan() sie nie linkuje |
---|
52 | #define finite(x) true //j.w. |
---|
53 | //#include <cstdlib> //RAND_MAX defined incorrectly |
---|
54 | //#ifdef BADA_SIMULATOR //...but only in simulator libs |
---|
55 | // #undef RAND_MAX |
---|
56 | // #define RAND_MAX 32768 //...this is the actual value used by rand() |
---|
57 | //#endif |
---|
58 | #endif |
---|
59 | |
---|
60 | |
---|
61 | //handling floating point exceptions |
---|
62 | void fpExceptInit(); //call once, before ...Enable/Disable |
---|
63 | void fpExceptEnable(); |
---|
64 | void fpExceptDisable(); |
---|
65 | |
---|
66 | // std::lerp can be used since c++20 (and has some guaranteed properties probably better than this basic formula) but apparently it is not a template |
---|
67 | template <typename Value, typename Linear> Value universal_lerp(Value a,Value b,Linear t) {return a*(1-t)+b*t;} |
---|
68 | |
---|
69 | #endif |
---|