From 24c7399ccb332172afb89848570f9f9e66e645e2 Mon Sep 17 00:00:00 2001 From: pur3mail Date: Mon, 22 Aug 2011 07:27:54 +0000 Subject: [PATCH] Version 0.30 : Rlyeh Mario's patch for Math Functions on VC++ --- TinyJS.cpp | 1 + TinyJS_MathFunctions.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/TinyJS.cpp b/TinyJS.cpp index 17cf4e2..99f0c64 100755 --- a/TinyJS.cpp +++ b/TinyJS.cpp @@ -94,6 +94,7 @@ Added shift operators Version 0.29 : Added new object via functions Fixed getString() for double on some platforms + Version 0.30 : Rlyeh Mario's patch for Math Functions on VC++ NOTE: Constructing an array with an initial length 'Array(5)' doesn't work diff --git a/TinyJS_MathFunctions.cpp b/TinyJS_MathFunctions.cpp index 4bd5023..ea5ef36 100755 --- a/TinyJS_MathFunctions.cpp +++ b/TinyJS_MathFunctions.cpp @@ -14,7 +14,7 @@ using namespace std; -#define k_E exp(1) +#define k_E exp(1.0) #define k_PI 3.1415926535897932384626433832795 #define F_ABS(a) ((a)>=0 ? (a) : (-(a))) @@ -32,6 +32,35 @@ using namespace std; #define scReturnInt(a) ( c->getReturnVar()->setInt(a) ) #define scReturnDouble(a) ( c->getReturnVar()->setDouble(a) ) +#ifdef _MSC_VER +namespace +{ + double asinh( const double &value ) + { + double returned; + + if(value>0) + returned = log(value + sqrt(value * value + 1)); + else + returned = -log(-value + sqrt(value * value + 1)); + + return(returned); + } + + double acosh( const double &value ) + { + double returned; + + if(value>0) + returned = log(value + sqrt(value * value - 1)); + else + returned = -log(-value + sqrt(value * value - 1)); + + return(returned); + } +} +#endif + //Math.abs(x) - returns absolute of given value void scMathAbs(CScriptVar *c, void *userdata) { if ( scIsInt("a") ) {