File indexing completed on 2024-05-12 17:22:32
0001 /* floatconst.c: constants for higher math functions */ 0002 /* 0003 Copyright (C) 2007, 2008 Wolf Lammen. 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation; either version 2 of the License , or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; see the file COPYING. If not, write to: 0017 0018 The Free Software Foundation, Inc. 0019 59 Temple Place, Suite 330 0020 Boston, MA 02111-1307 USA. 0021 0022 0023 You may contact the author by: 0024 e-mail: ookami1 <at> gmx <dot> de 0025 mail: Wolf Lammen 0026 Oertzweg 45 0027 22307 Hamburg 0028 Germany 0029 0030 *************************************************************************/ 0031 0032 #include "floatconst.h" 0033 0034 static char sExp[] = 0035 "2.7182818284""5904523536""0287471352""6624977572""4709369995" 0036 "9574966967""6277240766""3035354759""4571382178""5251664274" 0037 "2746639193""2003059921""8174135966""2904357290""0334295260" 0038 "5956307381""3232862794""3490763233""8298807531""9525101901" 0039 "1573834187"; 0040 0041 static char sLn2[] = 0042 "0.6931471805""5994530941""7232121458""1765680755""0013436025" 0043 "5254120680""0094933936""2196969471""5605863326""9964186875" 0044 "4200148102""0570685734"; 0045 0046 static char sLn3[] = 0047 "1.0986122886""6810969139""5245236922""5257046474""9055782274" 0048 "9451734694""3336374942""9321860896""6873615754""8137320887" 0049 "8797002906""5957865742"; 0050 0051 static char sLn7[] = 0052 "1.9459101490""5531330510""5352743443""1797296370""8472958186" 0053 "1188459390""1499375798""6275206926""7787658498""5878715269" 0054 "9306169420""5851140912"; 0055 0056 static char sLn10[] = 0057 "2.3025850929""9404568401""7991454684""3642076011""0148862877" 0058 "2976033327""9009675726""0967735248""0235997205""0895982983" 0059 "4196778404""2286248633"; 0060 0061 static char sPhi[] = 0062 "1.6180339887""4989484820""4586834365""6381177203""0917980576" 0063 "2862135448""6227052604""6281890244""9707207204""1893911374" 0064 "8475408807""5386891752""1266338622""2353693179""3180060766" 0065 "7263544333""8908659593""9582905638""3226613199""2829026788" 0066 "0675208766"; 0067 0068 static char sPi[] = 0069 "3.1415926535""8979323846""2643383279""5028841971""6939937510" 0070 "5820974944""5923078164""0628620899""8628034825""3421170679" 0071 "8214808651""3282306647""0938446095""5058223172""5359408128" 0072 "4811174502""8410270193""8521105559""6446229489""5493038196" 0073 "4428810976"; 0074 0075 static char sPiDiv2[] = 0076 "1.5707963267""9489661923""1321691639""7514420985""8469968755" 0077 "2910487472""2961539082""0314310449""9314017412""6710585339" 0078 "9107404325""6641153324"; 0079 0080 static char sPiDiv4[] = 0081 "0.7853981633""9744830961""5660845819""8757210492""9234984377" 0082 "6455243736""1480769541""0157155224""9657008706""3355292669" 0083 "9553702162""8320576662"; 0084 0085 static char s2Pi[] = 0086 "6.2831853071""7958647692""5286766559""0057683943""3879875021" 0087 "1641949889""1846156328""1257241799""7256069650""6842341359" 0088 "6429617302""6564613294"; 0089 0090 static char s1DivPi[] = 0091 "0.3183098861""8379067153""7767526745""0287240689""1929148091" 0092 "2897495334""6881177935""9526845307""0180227605""5325061719" 0093 "1214568545""3515916074"; 0094 0095 static char sLnSqrt2PiMinusHalf[] = 0096 "0.4189385332""0467274178""0329736405""6176398613""9747363778" 0097 "3412817151""5404827656""9592726039""7694743298""6359541976" 0098 "2200564662""4634337446"; 0099 0100 static char sSqrtPi[] = 0101 "1.7724538509""0551602729""8167483341""1451827975""4945612238" 0102 "7128213807""7898529112""8459103218""1374950656""7385446654" 0103 "1622682362""4282570666"; 0104 0105 static char s1DivSqrtPi[] = 0106 "0.5641895835""4775628694""8079451560""7725858440""5062932899" 0107 "8856844085""7217106424""6844149341""4486743660""2021073634" 0108 "4302834790""6361707352"; 0109 0110 static char s2DivSqrtPi[] = 0111 "1.1283791670""9551257389""6158903121""5451716881""0125865799" 0112 "7713688171""4434212849""3688298682""8973487320""4042147268" 0113 "8605669581""2723414703"; 0114 0115 static char* sBernoulli[] = 0116 { 0117 "1", 0118 "6", 0119 "1", 0120 "-30", 0121 "1", 0122 "42", 0123 "1", 0124 "-30", 0125 "5", 0126 "66", 0127 "691", 0128 "-2730", 0129 "7", 0130 "6", 0131 "3617", 0132 "-510", 0133 "43867", 0134 "798", 0135 "174611", 0136 "-330", 0137 "854513", 0138 "138", 0139 "236364091", 0140 "-2730", 0141 "8553103", 0142 "6", 0143 "23749461029", 0144 "-870", 0145 "8615841276005", 0146 "14322", 0147 "7709321041217", 0148 "-510", 0149 "2577687858367", 0150 "6", 0151 "26315271553053477373", 0152 "-1919190", 0153 "2929993913841559", 0154 "6", 0155 "261082718496449122051", 0156 "-13530", 0157 "1520097643918070802691", 0158 "1806", 0159 "27833269579301024235023", 0160 "-690", 0161 "596451111593912163277961", 0162 "282", 0163 "5609403368997817686249127547", 0164 "-46410", 0165 "495057205241079648212477525", 0166 "66", 0167 "801165718135489957347924991853", 0168 "-1590", 0169 "29149963634884862421418123812691", 0170 "798", 0171 "2479392929313226753685415739663229", 0172 "-870", 0173 "84483613348880041862046775994036021", 0174 "354", 0175 "1215233140483755572040304994079820246041491", 0176 "-56786730", 0177 "12300585434086858541953039857403386151", 0178 "6", 0179 "106783830147866529886385444979142647942017", 0180 "-510", 0181 "1472600022126335654051619428551932342241899101", 0182 "64722", 0183 "78773130858718728141909149208474606244347001", 0184 "-30", 0185 "1505381347333367003803076567377857208511438160235", 0186 "4686", 0187 "5827954961669944110438277244641067365282488301844260429", 0188 "-140100870", 0189 "34152417289221168014330073731472635186688307783087", 0190 "6", 0191 "24655088825935372707687196040585199904365267828865801", 0192 "-30", 0193 "414846365575400828295179035549542073492199375372400483487", 0194 "3318", 0195 "4603784299479457646935574969019046849794257872751288919656867", 0196 "-230010", 0197 "1677014149185145836823154509786269900207736027570253414881613", 0198 "498", 0199 "2024576195935290360231131160111731009989917391198090877281083932477", 0200 "-3404310", 0201 "660714619417678653573847847426261496277830686653388931761996983", 0202 "6", 0203 "1311426488674017507995511424019311843345750275572028644296919890574047", 0204 "-61410", 0205 "1179057279021082799884123351249215083775254949669647116231545215727922535", 0206 "272118", 0207 "1295585948207537527989427828538576749659341483719435143023316326829946247", 0208 "-1410", 0209 "1220813806579744469607301679413201203958508415202696621436215105284649447", 0210 "6", 0211 "-4.70038339580357310785752555350060606545967373697590579151397635641e73", 0212 "1", 0213 "1.13180434454842492706751862577339342678903659547507479181789935417e76", 0214 "1", 0215 "-2.83822495706937069592641563364817647382846809280128821282285317145e78", 0216 "1", 0217 "7.40642489796788506297508271409209841768797317880887066731161003487e80", 0218 "1", 0219 "-2.00964548027566044834656196727153631868672708225328766243461301989e83", 0220 "1", 0221 "5.66571700508059414457193460305193569614194682875104206213875644522e85", 0222 "1", 0223 "-1.65845111541362169158237133743199123014949626147254647274024668156e88", 0224 "1", 0225 "5.03688599504923774192894219151801548124423742649032141415256513225e90", 0226 "1", 0227 "-1.58614682376581863693634015729664387827409784127789638804728645143e93", 0228 "1", 0229 "5.17567436175456269840732406825071225612408492359305508590621669403e95", 0230 "1", 0231 "-1.74889218402171173396900258776181591451414761618265448726273472159e98", 0232 "1", 0233 "6.11605199949521852558245252642641677807677268467832007168432401127e100", 0234 "1", 0235 "-2.2122776912707834942288323456712932445573185054987780150566552693e103", 0236 "1", 0237 "8.27227767987709698542210624599845957312046505184335662838488529886e105", 0238 "1", 0239 "-3.19589251114157095835916343691808148735262766710991122731845042431e108", 0240 "1", 0241 "1.27500822233877929823100243029266798669571917963897732951605857354e111", 0242 "1", 0243 "-5.25009230867741338994028246245651754469198940377552432607801345222e113", 0244 "1", 0245 "2.2301817894241625209869298198838728143738272150875878542490550781e116", 0246 "1", 0247 "-9.76845219309552044386335133989802393011669026749856789710001706619e118", 0248 "1", 0249 "4.40983619784529542722726228748131691918757542655281147353197591401e121", 0250 "1", 0251 "-2.05085708864640888397293377275830154864565966904008359530873982755e124", 0252 "1" 0253 }; 0254 0255 floatstruct cBernoulliNum[68]; 0256 floatstruct cBernoulliDen[68]; 0257 0258 floatstruct c1; 0259 floatstruct c2; 0260 floatstruct c3; 0261 floatstruct c12; 0262 floatstruct c16; 0263 floatstruct cExp; 0264 floatstruct cMinus1; 0265 floatstruct cMinus20; 0266 floatstruct c1Div2; 0267 floatstruct cLn2; 0268 floatstruct cLn3; 0269 floatstruct cLn7; 0270 floatstruct cLn10; 0271 floatstruct cPhi; 0272 floatstruct cPi; 0273 floatstruct cPiDiv2; 0274 floatstruct cPiDiv4; 0275 floatstruct c2Pi; 0276 floatstruct c1DivPi; 0277 floatstruct cSqrtPi; 0278 floatstruct cLnSqrt2PiMinusHalf; 0279 floatstruct c1DivSqrtPi; 0280 floatstruct c2DivSqrtPi; 0281 floatstruct cMinus0_4; 0282 floatstruct cUnsignedBound; 0283 0284 int erfcdigits = 0; 0285 floatstruct erfccoeff[MAXERFCIDX]; 0286 floatstruct erfcalpha; 0287 floatstruct erfcalphasqr; 0288 floatstruct erfct2; 0289 floatstruct erfct3; 0290 0291 void 0292 floatmath_init() 0293 { 0294 int i, save; 0295 floatnum_init(); 0296 0297 save = float_setprecision(MAXDIGITS); 0298 float_create(&c1); 0299 float_setinteger(&c1, 1); 0300 float_create(&c2); 0301 float_setinteger(&c2, 2); 0302 float_create(&c3); 0303 float_setinteger(&c3, 3); 0304 float_create(&c12); 0305 float_setinteger(&c12, 12); 0306 float_create(&c16); 0307 float_setinteger(&c16, 16); 0308 float_create(&cMinus1); 0309 float_setinteger(&cMinus1, -1); 0310 float_create(&cMinus20); 0311 float_setinteger(&cMinus20, -20); 0312 float_create(&c1Div2); 0313 float_setscientific(&c1Div2, ".5", NULLTERMINATED); 0314 float_create(&cExp); 0315 float_setscientific(&cExp, sExp, NULLTERMINATED); 0316 float_create(&cLn2); 0317 float_setscientific(&cLn2, sLn2, NULLTERMINATED); 0318 float_create(&cLn3); 0319 float_setscientific(&cLn3, sLn3, NULLTERMINATED); 0320 float_create(&cLn7); 0321 float_setscientific(&cLn7, sLn7, NULLTERMINATED); 0322 float_create(&cLn10); 0323 float_setscientific(&cLn10, sLn10, NULLTERMINATED); 0324 float_create(&cPhi); 0325 float_setscientific(&cPhi, sPhi, NULLTERMINATED); 0326 float_create(&cPi); 0327 float_setscientific(&cPi, sPi, NULLTERMINATED); 0328 float_create(&cPiDiv2); 0329 float_setscientific(&cPiDiv2, sPiDiv2, NULLTERMINATED); 0330 float_create(&cPiDiv4); 0331 float_setscientific(&cPiDiv4, sPiDiv4, NULLTERMINATED); 0332 float_create(&c2Pi); 0333 float_setscientific(&c2Pi, s2Pi, NULLTERMINATED); 0334 float_create(&c1DivPi); 0335 float_setscientific(&c1DivPi, s1DivPi, NULLTERMINATED); 0336 float_create(&cSqrtPi); 0337 float_setscientific(&cSqrtPi, sSqrtPi, NULLTERMINATED); 0338 float_create(&cLnSqrt2PiMinusHalf); 0339 float_setscientific(&cLnSqrt2PiMinusHalf, sLnSqrt2PiMinusHalf, 0340 NULLTERMINATED); 0341 float_create(&c1DivSqrtPi); 0342 float_setscientific(&c1DivSqrtPi, s1DivSqrtPi, NULLTERMINATED); 0343 float_create(&c2DivSqrtPi); 0344 float_setscientific(&c2DivSqrtPi, s2DivSqrtPi, NULLTERMINATED); 0345 float_create(&cMinus0_4); 0346 float_setscientific(&cMinus0_4, "-.4", NULLTERMINATED); 0347 for (i = -1; ++i < MAXBERNOULLIIDX;) 0348 { 0349 float_create(&cBernoulliNum[i]); 0350 float_create(&cBernoulliDen[i]); 0351 float_setscientific(&cBernoulliNum[i], sBernoulli[2*i], NULLTERMINATED); 0352 float_setscientific(&cBernoulliDen[i], sBernoulli[2*i+1], NULLTERMINATED); 0353 } 0354 float_create(&cUnsignedBound); 0355 float_copy(&cUnsignedBound, &c1, EXACT); 0356 for (i = -1; ++i < 2*(int)sizeof(unsigned);) 0357 float_mul(&cUnsignedBound, &c16, &cUnsignedBound, EXACT); 0358 for (i = -1; ++i < MAXERFCIDX;) 0359 float_create(&erfccoeff[i]); 0360 float_create(&erfcalpha); 0361 float_create(&erfcalphasqr); 0362 float_create(&erfct2); 0363 float_create(&erfct3); 0364 float_setprecision(save); 0365 } 0366 0367 void 0368 floatmath_exit() 0369 { 0370 int i; 0371 0372 float_free(&c1); 0373 float_free(&c2); 0374 float_free(&c3); 0375 float_free(&c12); 0376 float_free(&c16); 0377 float_free(&cMinus1); 0378 float_free(&cMinus20); 0379 float_free(&c1Div2); 0380 float_free(&cExp); 0381 float_free(&cLn2); 0382 float_free(&cLn3); 0383 float_free(&cLn7); 0384 float_free(&cLn10); 0385 float_free(&cPhi); 0386 float_free(&cPi); 0387 float_free(&cPiDiv2); 0388 float_free(&cPiDiv4); 0389 float_free(&c2Pi); 0390 float_free(&c1DivPi); 0391 float_free(&cSqrtPi); 0392 float_free(&cLnSqrt2PiMinusHalf); 0393 float_free(&c1DivSqrtPi); 0394 float_free(&c2DivSqrtPi); 0395 float_free(&cMinus0_4); 0396 for (i = -1; ++i < MAXBERNOULLIIDX;) 0397 { 0398 float_free(&cBernoulliNum[i]); 0399 float_free(&cBernoulliDen[i]); 0400 } 0401 float_free(&cUnsignedBound); 0402 for (i = -1; ++i < MAXERFCIDX;) 0403 float_free(&erfccoeff[i]); 0404 float_free(&erfcalpha); 0405 float_free(&erfcalphasqr); 0406 float_free(&erfct2); 0407 float_free(&erfct3); 0408 }