source: cpp/common/nonstd_math.h @ 875

Last change on this file since 875 was 835, checked in by Maciej Komosinski, 6 years ago

ISO C++17 compliance including NULL, nullptr, templates and pointer conversions

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2018  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 wczeœniej <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"
23RandomGenerator& rndGetInstance();
24
25#define rnd01 (rndGetInstance().getDouble())
26#define rnd0N(limit) (rndGetInstance().getDouble()*(limit))
27#define randomN(limit) ((unsigned int)(rndGetInstance().getDouble()*(limit)))
28#define setRandomSeed(seed) rndGetInstance().setSeed(seed)
29#define setRandomRandomSeed() rndGetInstance().randomize()
30
31
32//floating point specific numbers
33#include "stdlib.h"
34
35#ifdef __BORLANDC__
36        #include <float.h>
37        #define isnan(x) _isnan(x) //http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c
38        #define finite(x) _finite(x)
39#endif
40
41#ifdef LINUX
42  #define _isnan(a) isnan(a)
43#endif
44
45#ifdef IPHONE
46        #define finite(x) (!isinf(x))
47  #define _isnan(a) isnan(a)
48#endif
49
50
51#if defined SHP
52 //#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"
53 #define isnan(x) false //isnan() sie nie linkuje
54 #define finite(x) true //j.w.
55 //#include <cstdlib> //RAND_MAX defined incorrectly
56 //#ifdef BADA_SIMULATOR //...but only in simulator libs
57 // #undef RAND_MAX
58 // #define RAND_MAX 32768 //...this is the actual value used by rand()
59 //#endif
60#endif
61
62
63//handling floating point exceptions
64void fpExceptInit(); //call once, before ...Enable/Disable
65void fpExceptEnable();
66void fpExceptDisable();
67
68#endif
69
Note: See TracBrowser for help on using the repository browser.