source: cpp/common/nonstd_math.cpp @ 119

Last change on this file since 119 was 109, checked in by sz, 11 years ago

source reorganization (see README)
new feature added: part/joint shapes (see frams/_demos/part_shapes.cpp)

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#include "nonstd_math.h"
2
3RandomGenerator& rndGetInstance()
4{
5static RandomGenerator rnd(0);
6return rnd;
7}
8
9
10
11
12#ifdef _WIN32 //http://stackoverflow.com/questions/2170385/c-math-functions
13double round(double val)
14{   
15    return floor(val + 0.5);
16}
17#endif
18
19
20
21
22#if defined LINUX || defined TIZEN
23
24#include <fenv.h>
25
26void fpExceptInit()
27{}
28
29void fpExceptEnable()
30{
31feclearexcept(FE_DIVBYZERO | FE_OVERFLOW);
32feenableexcept(FE_DIVBYZERO | FE_OVERFLOW);
33}
34
35void fpExceptDisable()
36{
37fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW);
38}
39
40#endif
41
42
43#ifdef IPHONE
44
45#include <fenv.h>
46
47void fpExceptInit()
48{}
49
50void fpExceptEnable()
51{
52feclearexcept(FE_DIVBYZERO | FE_OVERFLOW);
53//feenableexcept(FE_DIVBYZERO | FE_OVERFLOW);
54}
55
56void fpExceptDisable()
57{
58//fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW);
59}
60#endif
61
62
63#ifdef __BORLANDC__
64
65#include "framsg.h"
66
67unsigned int fp_control_word_std;
68unsigned int fp_control_word_muted;
69
70void fpExceptInit()
71{
72        //unsigned int was=_clear87();
73        //FMprintf("","fpExceptInit",FMLV_INFO,"control87 status before clear was %08x", was);
74        fp_control_word_std=_control87(0, 0);             //4978 = 1001101110010
75        // Make the new fp env same as the old one, except for the changes we're going to make
76        fp_control_word_muted = fp_control_word_std | EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW | EM_UNDERFLOW | EM_INEXACT;  //4991 = 1001101111111
77}
78
79void fpExceptEnable()
80{
81        unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception...
82        //FMprintf("","fpExceptEnable ",FMLV_INFO,"control87 status before clear was %08x", was);
83        _control87(fp_control_word_std, 0xffffffff);
84        //FMprintf("","fpExceptEnable ",FMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
85}
86
87void fpExceptDisable()
88{
89        unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception...
90        //FMprintf("","fpExceptDisable",FMLV_INFO,"control87 status before clear was %08x", was);
91        _control87(fp_control_word_muted, 0xffffffff);
92        //FMprintf("","fpExceptDisable",FMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo
93}
94
95#endif
96
97
98
99#ifdef _MSC_VER
100//Moznaby zrobic tak jak pod linuxem czyli wlaczyc exceptiony na poczatku i wylaczac na chwile przy dzieleniu w extvalue.
101//To by pozwoli³o na wy³apanie pod visualem z³ych sytuacji kiedy framsy licz¹ na NaN, INF itp.
102//http://stackoverflow.com/questions/2769814/how-do-i-use-try-catch-to-catch-floating-point-errors
103void fpExceptInit() {}
104void fpExceptEnable() {}
105void fpExceptDisable() {}
106#endif
107
Note: See TracBrowser for help on using the repository browser.