14"double Intg(double n)\n"
19" return trunc(n)-1;\n"
21" return trunc(n)+1;\n"
25"= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
26"9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n";
28const char RoundDecl[] =
"double Round(double fValue);\n";
31"double Round(double fValue)\n"
33" if ( fValue == 0.0 )\n"
38" if ( fValue > 0.0 )\n"
39" nExp = ( floor( log10( fValue ) ) );\n"
42" int nIndex = 15 - nExp;\n"
43" if ( nIndex > 15 )\n"
45" else if ( nIndex <= 1 )\n"
47" fValue = floor( fValue + 0.5 + nCorrVal[nIndex] );\n"
51const char bikDecl[] =
"double bik(double n,double k);\n";
53"double bik(double n,double k)\n"
61" nVal1 = nVal1 * n;\n"
62" nVal2 = nVal2 * k;\n"
66" return (nVal1 / nVal2);\n"
71"double local_coth(double n)\n"
73" double a = exp(n);\n"
74" double b = exp(-n);\n"
75" double nVal = (a + b) / (a - b);\n"
81"double local_cosh(double n)\n"
83" double nVal = (exp(n) + exp(-n)) / 2;\n"
86const char atan2Decl[] =
"double arctan2(double y, double x);\n";
88"double arctan2(double y, double x)\n"
91" return x >= 0 ? 0.0 : M_PI;\n"
92" double a,num,den,tmpPi;\n"
95" if (fabs(x) >= fabs(y))\n"
103" if(fabs(x) < fabs(y))\n"
110" a = atan(num/den);\n"
111" a = flag==1?a:-a;\n"
112" a = a + (y >= 0.0 ? tmpPi : -tmpPi);\n"
118"int is_representable_integer(double a) {\n"
119" long kMaxInt = (1L << 53) - 1;\n"
120" if (a <= (double)kMaxInt)\n"
122" long nInt = (long)a;\n"
124" return (nInt <= kMaxInt &&\n"
125" (!((fInt = (double)nInt) < a) && !(fInt > a)));\n"
132"int approx_equal(double a, double b) {\n"
133" double e48 = 1.0 / (16777216.0 * 16777216.0);\n"
134" double e44 = e48 * 16.0;\n"
137" if (a == 0.0 || b == 0.0)\n"
139" double d = fabs(a - b);\n"
140" if (!isfinite(d))\n"
141" return 0; // Nan or Inf involved\n"
142" if (d > ((a = fabs(a)) * e44) || d > ((b = fabs(b)) * e44))\n"
144" if (is_representable_integer(d) && is_representable_integer(a) && is_representable_integer(b))\n"
145" return 0; // special case for representable integers.\n"
146" return (d < a * e48 && d < b * e48);\n"
151"double fsum_approx(double a, double b) {\n"
152" if ( ((a < 0.0 && b > 0.0) || (b < 0.0 && a > 0.0))\n"
153" && approx_equal( a, -b ) )\n"
160"double fsub_approx(double a, double b) {\n"
161" if ( ((a < 0.0 && b < 0.0) || (a > 0.0 && b > 0.0)) && approx_equal( a, b ) )\n"
168"double value_approx( double fValue )\n"
170" const double fBigInt = 2199023255552.0;\n"
171" if (fValue == 0.0 || fValue == HUGE_VAL || !isfinite(fValue))\n"
173" double fOrigValue = fValue;\n"
174" fValue = fabs(fValue);\n"
175" if (fValue > fBigInt)\n"
176" return fOrigValue;\n"
177" if (is_representable_integer(fValue))\n"
178" return fOrigValue;\n"
179" int nExp = (int)(floor(log10(fValue)));\n"
180" nExp = 14 - nExp;\n"
181" double fExpValue = pow(10.0,nExp);\n"
182" fValue *= fExpValue;\n"
183" if (!isfinite(fValue))\n"
184" return fOrigValue;\n"
185" fValue = round(fValue);\n"
186" fValue /= fExpValue;\n"
187" if (!isfinite(fValue))\n"
188" return fOrigValue;\n"
189" return copysign(fValue, fOrigValue);\n"
195const char cell_equalDecl[] =
"bool cell_equal(double a, double b, bool a_is_string, bool b_is_string);\n";
197"bool cell_equal(double a, double b, bool a_is_string, bool b_is_string) {\n"
198" if( !a_is_string && !b_is_string )\n"
199" return approx_equal( isnan(a) ? 0 : a, isnan(b) ? 0 : b );\n"
200" if( a_is_string && b_is_string )\n"
203" if(( a_is_string && a == 0 && isnan(b)) || ( b_is_string && b == 0 && isnan(a)))\n"
const char fsum_approxDecl[]
const char local_cothDecl[]
const char is_representable_integerDecl[]
const char atan2Content[]
const char fsub_approxDecl[]
const char approx_equalDecl[]
const char approx_equal[]
const char local_coshDecl[]
const char value_approxDecl[]
const char value_approx[]
const char Math_IntgDecl[]
const char nCorrValDecl[]
const char cell_equalDecl[]
const char is_representable_integer[]