1 2/* 3 * M_APM - mapmcnst.c 4 * 5 * Copyright (C) 1999 - 2007 Michael C. Ring 6 * 7 * Permission to use, copy, and distribute this software and its 8 * documentation for any purpose with or without fee is hereby granted, 9 * provided that the above copyright notice appear in all copies and 10 * that both that copyright notice and this permission notice appear 11 * in supporting documentation. 12 * 13 * Permission to modify the software is granted. Permission to distribute 14 * the modified code is granted. Modifications are to be distributed by 15 * using the file 'license.txt' as a template to modify the file header. 16 * 'license.txt' is available in the official MAPM distribution. 17 * 18 * This software is provided "as is" without express or implied warranty. 19 */ 20 21/* 22 * $Id: mapmcnst.c,v 1.24 2007/12/03 01:51:16 mike Exp $ 23 * 24 * This file contains declarations and initializes the constants 25 * used throughout the library. 26 * 27 * $Log: mapmcnst.c,v $ 28 * Revision 1.24 2007/12/03 01:51:16 mike 29 * Update license 30 * 31 * Revision 1.23 2003/05/06 21:28:53 mike 32 * add lib version functions 33 * 34 * Revision 1.22 2003/03/30 21:14:16 mike 35 * add local copies of log(2) and log(10) 36 * 37 * Revision 1.21 2002/11/03 22:45:29 mike 38 * Updated function parameters to use the modern style 39 * 40 * Revision 1.20 2002/05/17 22:40:25 mike 41 * call m_apm_init from cpp_precision to init the library 42 * if it hasn't been done yet. 43 * 44 * Revision 1.19 2001/07/16 19:40:12 mike 45 * add function M_free_all_cnst 46 * 47 * Revision 1.18 2001/02/07 19:17:58 mike 48 * eliminate MM_skip_limit_PI_check 49 * 50 * Revision 1.17 2000/05/19 16:31:02 mike 51 * add local copies for PI variables 52 * 53 * Revision 1.16 2000/05/04 23:52:03 mike 54 * added new constant, 256R. 55 * renamed _008 to _125R 56 * 57 * Revision 1.15 2000/04/11 18:44:21 mike 58 * no longer need the constant 'Fifteen' 59 * 60 * Revision 1.14 2000/04/05 20:12:53 mike 61 * add C++ min precision function 62 * 63 * Revision 1.13 1999/07/09 22:47:48 mike 64 * add skip limit PI check 65 * 66 * Revision 1.12 1999/07/08 23:34:50 mike 67 * change constant 68 * 69 * Revision 1.11 1999/07/08 22:58:08 mike 70 * add new constant 71 * 72 * Revision 1.10 1999/06/23 01:09:53 mike 73 * added new constant 15 74 * 75 * Revision 1.9 1999/06/20 23:32:30 mike 76 * added new constants 77 * 78 * Revision 1.8 1999/06/20 19:24:14 mike 79 * delete constants no longer needed 80 * 81 * Revision 1.7 1999/06/20 18:57:29 mike 82 * fixed missing init for new constants 83 * 84 * Revision 1.6 1999/06/20 18:53:44 mike 85 * added more constants 86 * 87 * Revision 1.5 1999/05/31 23:50:30 mike 88 * delete constants no longer needed 89 * 90 * Revision 1.4 1999/05/14 19:50:22 mike 91 * added more constants with more digits 92 * 93 * Revision 1.3 1999/05/12 20:53:08 mike 94 * added more constants 95 * 96 * Revision 1.2 1999/05/10 21:52:24 mike 97 * added some comments 98 * 99 * Revision 1.1 1999/05/10 20:56:31 mike 100 * Initial revision 101 */ 102 103#include "m_apm_lc.h" 104 105int MM_lc_PI_digits = 0; 106int MM_lc_log_digits; 107int MM_cpp_min_precision; /* only used in C++ wrapper */ 108 109M_APM MM_Zero = NULL; 110M_APM MM_One = NULL; 111M_APM MM_Two = NULL; 112M_APM MM_Three = NULL; 113M_APM MM_Four = NULL; 114M_APM MM_Five = NULL; 115M_APM MM_Ten = NULL; 116M_APM MM_0_5 = NULL; 117M_APM MM_E = NULL; 118M_APM MM_PI = NULL; 119M_APM MM_HALF_PI = NULL; 120M_APM MM_2_PI = NULL; 121M_APM MM_lc_PI = NULL; 122M_APM MM_lc_HALF_PI = NULL; 123M_APM MM_lc_2_PI = NULL; 124M_APM MM_lc_log2 = NULL; 125M_APM MM_lc_log10 = NULL; 126M_APM MM_lc_log10R = NULL; 127M_APM MM_0_85 = NULL; 128M_APM MM_5x_125R = NULL; 129M_APM MM_5x_64R = NULL; 130M_APM MM_5x_256R = NULL; 131M_APM MM_5x_Eight = NULL; 132M_APM MM_5x_Sixteen = NULL; 133M_APM MM_5x_Twenty = NULL; 134M_APM MM_LOG_E_BASE_10 = NULL; 135M_APM MM_LOG_10_BASE_E = NULL; 136M_APM MM_LOG_2_BASE_E = NULL; 137M_APM MM_LOG_3_BASE_E = NULL; 138 139 140static char MM_cnst_PI[] = 141"3.1415926535897932384626433832795028841971693993751058209749445923078\ 1421640628620899862803482534211706798214808651328230664709384460955"; 143 144static char MM_cnst_E[] = 145"2.7182818284590452353602874713526624977572470936999595749669676277240\ 14676630353547594571382178525166427427466391932003059921817413596629"; 147 148static char MM_cnst_log_2[] = 149"0.6931471805599453094172321214581765680755001343602552541206800094933\ 15093621969694715605863326996418687542001481020570685733685520235758"; 151 152static char MM_cnst_log_3[] = 153"1.0986122886681096913952452369225257046474905578227494517346943336374\ 1549429321860896687361575481373208878797002906595786574236800422593"; 155 156static char MM_cnst_log_10[] = 157"2.3025850929940456840179914546843642076011014886287729760333279009675\ 1587260967735248023599720508959829834196778404228624863340952546508"; 159 160static char MM_cnst_1_log_10[] = 161"0.4342944819032518276511289189166050822943970058036665661144537831658\ 16264649208870774729224949338431748318706106744766303733641679287159"; 163 164/* 165 * the following constants have ~520 digits each, if needed 166 */ 167 168/* 169static char MM_cnst_PI[] = 170"3.1415926535897932384626433832795028841971693993751058209749445923078\ 171164062862089986280348253421170679821480865132823066470938446095505822\ 172317253594081284811174502841027019385211055596446229489549303819644288\ 173109756659334461284756482337867831652712019091456485669234603486104543\ 174266482133936072602491412737245870066063155881748815209209628292540917\ 175153643678925903600113305305488204665213841469519415116094330572703657\ 176595919530921861173819326117931051185480744623799627495673518857527248\ 17791227938183011949129833673362440656643"; 178 179static char MM_cnst_E[] = 180"2.7182818284590452353602874713526624977572470936999595749669676277240\ 181766303535475945713821785251664274274663919320030599218174135966290435\ 182729003342952605956307381323286279434907632338298807531952510190115738\ 183341879307021540891499348841675092447614606680822648001684774118537423\ 184454424371075390777449920695517027618386062613313845830007520449338265\ 185602976067371132007093287091274437470472306969772093101416928368190255\ 186151086574637721112523897844250569536967707854499699679468644549059879\ 1873163688923009879312773617821542499923"; 188 189static char MM_cnst_log_2[] = 190"0.6931471805599453094172321214581765680755001343602552541206800094933\ 191936219696947156058633269964186875420014810205706857336855202357581305\ 192570326707516350759619307275708283714351903070386238916734711233501153\ 193644979552391204751726815749320651555247341395258829504530070953263666\ 194426541042391578149520437404303855008019441706416715186447128399681717\ 195845469570262716310645461502572074024816377733896385506952606683411372\ 196738737229289564935470257626520988596932019650585547647033067936544325\ 19747632744951250406069438147104689946506"; 198 199static char MM_cnst_log_3[] = 200"1.0986122886681096913952452369225257046474905578227494517346943336374\ 201942932186089668736157548137320887879700290659578657423680042259305198\ 202210528018707672774106031627691833813671793736988443609599037425703167\ 203959115211455919177506713470549401667755802222031702529468975606901065\ 204215056428681380363173732985777823669916547921318181490200301038236301\ 205222486527481982259910974524908964580534670088459650857484441190188570\ 206876474948670796130858294116021661211840014098255143919487688936798494\ 2073022557315353296853452952514592138765"; 208 209static char MM_cnst_log_10[] = 210"2.3025850929940456840179914546843642076011014886287729760333279009675\ 211726096773524802359972050895982983419677840422862486334095254650828067\ 212566662873690987816894829072083255546808437998948262331985283935053089\ 213653777326288461633662222876982198867465436674744042432743651550489343\ 214149393914796194044002221051017141748003688084012647080685567743216228\ 215355220114804663715659121373450747856947683463616792101806445070648000\ 216277502684916746550586856935673420670581136429224554405758925724208241\ 21731469568901675894025677631135691929203"; 218 219static char MM_cnst_1_log_10[] = 220"0.4342944819032518276511289189166050822943970058036665661144537831658\ 221646492088707747292249493384317483187061067447663037336416792871589639\ 222065692210646628122658521270865686703295933708696588266883311636077384\ 223905142844348666768646586085135561482123487653435434357317253835622281\ 224395603048646652366095539377356176323431916710991411597894962993512457\ 225934926357655469077671082419150479910989674900103277537653570270087328\ 226550951731440674697951899513594088040423931518868108402544654089797029\ 22786328682876262414401345704354613292060"; 228*/ 229 230 231/****************************************************************************/ 232char *m_apm_lib_version(char *v) 233{ 234strcpy(v, MAPM_LIB_VERSION); 235return(v); 236} 237/****************************************************************************/ 238char *m_apm_lib_short_version(char *v) 239{ 240strcpy(v, MAPM_LIB_SHORT_VERSION); 241return(v); 242} 243/****************************************************************************/ 244void M_free_all_cnst() 245{ 246if (MM_lc_PI_digits != 0) 247 { 248 m_apm_free(MM_Zero); 249 m_apm_free(MM_One); 250 m_apm_free(MM_Two); 251 m_apm_free(MM_Three); 252 m_apm_free(MM_Four); 253 m_apm_free(MM_Five); 254 m_apm_free(MM_Ten); 255 m_apm_free(MM_0_5); 256 m_apm_free(MM_LOG_2_BASE_E); 257 m_apm_free(MM_LOG_3_BASE_E); 258 m_apm_free(MM_E); 259 m_apm_free(MM_PI); 260 m_apm_free(MM_HALF_PI); 261 m_apm_free(MM_2_PI); 262 m_apm_free(MM_lc_PI); 263 m_apm_free(MM_lc_HALF_PI); 264 m_apm_free(MM_lc_2_PI); 265 m_apm_free(MM_lc_log2); 266 m_apm_free(MM_lc_log10); 267 m_apm_free(MM_lc_log10R); 268 m_apm_free(MM_0_85); 269 m_apm_free(MM_5x_125R); 270 m_apm_free(MM_5x_64R); 271 m_apm_free(MM_5x_256R); 272 m_apm_free(MM_5x_Eight); 273 m_apm_free(MM_5x_Sixteen); 274 m_apm_free(MM_5x_Twenty); 275 m_apm_free(MM_LOG_E_BASE_10); 276 m_apm_free(MM_LOG_10_BASE_E); 277 278 MM_lc_PI_digits = 0; 279 } 280} 281/****************************************************************************/ 282void M_init_trig_globals() 283{ 284MM_lc_PI_digits = VALID_DECIMAL_PLACES; 285MM_lc_log_digits = VALID_DECIMAL_PLACES; 286MM_cpp_min_precision = 30; 287 288MM_Zero = m_apm_init(); 289MM_One = m_apm_init(); 290MM_Two = m_apm_init(); 291MM_Three = m_apm_init(); 292MM_Four = m_apm_init(); 293MM_Five = m_apm_init(); 294MM_Ten = m_apm_init(); 295MM_0_5 = m_apm_init(); 296MM_LOG_2_BASE_E = m_apm_init(); 297MM_LOG_3_BASE_E = m_apm_init(); 298MM_E = m_apm_init(); 299MM_PI = m_apm_init(); 300MM_HALF_PI = m_apm_init(); 301MM_2_PI = m_apm_init(); 302MM_lc_PI = m_apm_init(); 303MM_lc_HALF_PI = m_apm_init(); 304MM_lc_2_PI = m_apm_init(); 305MM_lc_log2 = m_apm_init(); 306MM_lc_log10 = m_apm_init(); 307MM_lc_log10R = m_apm_init(); 308MM_0_85 = m_apm_init(); 309MM_5x_125R = m_apm_init(); 310MM_5x_64R = m_apm_init(); 311MM_5x_256R = m_apm_init(); 312MM_5x_Eight = m_apm_init(); 313MM_5x_Sixteen = m_apm_init(); 314MM_5x_Twenty = m_apm_init(); 315MM_LOG_E_BASE_10 = m_apm_init(); 316MM_LOG_10_BASE_E = m_apm_init(); 317 318m_apm_set_string(MM_One, "1"); 319m_apm_set_string(MM_Two, "2"); 320m_apm_set_string(MM_Three, "3"); 321m_apm_set_string(MM_Four, "4"); 322m_apm_set_string(MM_Five, "5"); 323m_apm_set_string(MM_Ten, "10"); 324m_apm_set_string(MM_0_5, "0.5"); 325m_apm_set_string(MM_0_85, "0.85"); 326 327m_apm_set_string(MM_5x_125R, "8.0E-3"); 328m_apm_set_string(MM_5x_64R, "1.5625E-2"); 329m_apm_set_string(MM_5x_256R, "3.90625E-3"); 330m_apm_set_string(MM_5x_Eight, "8"); 331m_apm_set_string(MM_5x_Sixteen, "16"); 332m_apm_set_string(MM_5x_Twenty, "20"); 333 334m_apm_set_string(MM_LOG_2_BASE_E, MM_cnst_log_2); 335m_apm_set_string(MM_LOG_3_BASE_E, MM_cnst_log_3); 336m_apm_set_string(MM_LOG_10_BASE_E, MM_cnst_log_10); 337m_apm_set_string(MM_LOG_E_BASE_10, MM_cnst_1_log_10); 338 339m_apm_set_string(MM_lc_log2, MM_cnst_log_2); 340m_apm_set_string(MM_lc_log10, MM_cnst_log_10); 341m_apm_set_string(MM_lc_log10R, MM_cnst_1_log_10); 342 343m_apm_set_string(MM_E, MM_cnst_E); 344m_apm_set_string(MM_PI, MM_cnst_PI); 345m_apm_multiply(MM_HALF_PI, MM_PI, MM_0_5); 346m_apm_multiply(MM_2_PI, MM_PI, MM_Two); 347 348m_apm_copy(MM_lc_PI, MM_PI); 349m_apm_copy(MM_lc_HALF_PI, MM_HALF_PI); 350m_apm_copy(MM_lc_2_PI, MM_2_PI); 351} 352/****************************************************************************/ 353void m_apm_cpp_precision(int digits) 354{ 355if (MM_lc_PI_digits == 0) 356 { 357 m_apm_free(m_apm_init()); 358 } 359 360if (digits >= 2) 361 MM_cpp_min_precision = digits; 362else 363 MM_cpp_min_precision = 2; 364} 365/****************************************************************************/ 366