source: cpp/common/nonstd_math.cpp @ 139

Last change on this file since 139 was 135, checked in by sz, 11 years ago

neuron layout algorithm (for schematic drawing), usage example in frams/_demos/neuro_layout_test.cpp

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