// This file is a part of the Framsticks GDK. // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. // Refer to http://www.framsticks.com/ for further information. #include "nonstd_math.h" RandomGenerator& rndGetInstance() { static RandomGenerator rnd(0); return rnd; } #if defined __BORLANDC__ || (_MSC_VER <= 1700) double round(double val) //http://stackoverflow.com/questions/2170385/c-math-functions { return floor(val + 0.5); } #endif #if defined LINUX || defined TIZEN #include void fpExceptInit() {} void fpExceptEnable() { feclearexcept(FE_DIVBYZERO | FE_OVERFLOW); feenableexcept(FE_DIVBYZERO | FE_OVERFLOW); } void fpExceptDisable() { fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW); } #endif #ifdef IPHONE #include void fpExceptInit() {} void fpExceptEnable() { feclearexcept(FE_DIVBYZERO | FE_OVERFLOW); //feenableexcept(FE_DIVBYZERO | FE_OVERFLOW); } void fpExceptDisable() { //fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW); } #endif #ifdef __BORLANDC__ #include "framsg.h" unsigned int fp_control_word_std; unsigned int fp_control_word_muted; void fpExceptInit() { //unsigned int was=_clear87(); //FMprintf("","fpExceptInit",FMLV_INFO,"control87 status before clear was %08x", was); fp_control_word_std=_control87(0, 0); //4978 = 1001101110010 // Make the new fp env same as the old one, except for the changes we're going to make fp_control_word_muted = fp_control_word_std | EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW | EM_UNDERFLOW | EM_INEXACT; //4991 = 1001101111111 } void fpExceptEnable() { unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception... //FMprintf("","fpExceptEnable ",FMLV_INFO,"control87 status before clear was %08x", was); _control87(fp_control_word_std, 0xffffffff); //FMprintf("","fpExceptEnable ",FMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo } void fpExceptDisable() { unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception... //FMprintf("","fpExceptDisable",FMLV_INFO,"control87 status before clear was %08x", was); _control87(fp_control_word_muted, 0xffffffff); //FMprintf("","fpExceptDisable",FMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo } #endif #ifdef _MSC_VER //Moznaby zrobic tak jak pod linuxem czyli wlaczyc exceptiony na poczatku i wylaczac na chwile przy dzieleniu w extvalue. //To by pozwoliło na wyłapanie pod visualem złych sytuacji kiedy framsy liczą na NaN, INF itp. //http://stackoverflow.com/questions/2769814/how-do-i-use-try-catch-to-catch-floating-point-errors void fpExceptInit() {} void fpExceptEnable() {} void fpExceptDisable() {} #endif