Library for big numbers from http://www.ttmath.org/

Dependents:   PIDHeater82 Conceptcontroller_v_1_0 AlarmClockApp COG4050_adxl355_tilt ... more

TTMath is a small library which allows one to perform arithmetic operations with big unsigned integer, big signed integer and big floating point numbers. It provides standard mathematical operations like adding, subtracting, multiplying, dividing.

TTMath is BSD Licensed (new/modified BSD)

For more information about ttmath see http://www.ttmath.org/

Committer:
stevep
Date:
Tue Jul 30 18:43:48 2013 +0000
Revision:
0:04a9f72bbca7
v0.9.3 of ttmath

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stevep 0:04a9f72bbca7 1 /*
stevep 0:04a9f72bbca7 2 * This file is a part of TTMath Mathematical Library
stevep 0:04a9f72bbca7 3 * and is distributed under the (new) BSD licence.
stevep 0:04a9f72bbca7 4 * Author: Tomasz Sowa <t.sowa@ttmath.org>
stevep 0:04a9f72bbca7 5 */
stevep 0:04a9f72bbca7 6
stevep 0:04a9f72bbca7 7 /*
stevep 0:04a9f72bbca7 8 * Copyright (c) 2006-2010, Tomasz Sowa
stevep 0:04a9f72bbca7 9 * All rights reserved.
stevep 0:04a9f72bbca7 10 *
stevep 0:04a9f72bbca7 11 * Redistribution and use in source and binary forms, with or without
stevep 0:04a9f72bbca7 12 * modification, are permitted provided that the following conditions are met:
stevep 0:04a9f72bbca7 13 *
stevep 0:04a9f72bbca7 14 * * Redistributions of source code must retain the above copyright notice,
stevep 0:04a9f72bbca7 15 * this list of conditions and the following disclaimer.
stevep 0:04a9f72bbca7 16 *
stevep 0:04a9f72bbca7 17 * * Redistributions in binary form must reproduce the above copyright
stevep 0:04a9f72bbca7 18 * notice, this list of conditions and the following disclaimer in the
stevep 0:04a9f72bbca7 19 * documentation and/or other materials provided with the distribution.
stevep 0:04a9f72bbca7 20 *
stevep 0:04a9f72bbca7 21 * * Neither the name Tomasz Sowa nor the names of contributors to this
stevep 0:04a9f72bbca7 22 * project may be used to endorse or promote products derived
stevep 0:04a9f72bbca7 23 * from this software without specific prior written permission.
stevep 0:04a9f72bbca7 24 *
stevep 0:04a9f72bbca7 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
stevep 0:04a9f72bbca7 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
stevep 0:04a9f72bbca7 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
stevep 0:04a9f72bbca7 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
stevep 0:04a9f72bbca7 29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
stevep 0:04a9f72bbca7 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
stevep 0:04a9f72bbca7 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
stevep 0:04a9f72bbca7 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
stevep 0:04a9f72bbca7 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
stevep 0:04a9f72bbca7 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
stevep 0:04a9f72bbca7 35 * THE POSSIBILITY OF SUCH DAMAGE.
stevep 0:04a9f72bbca7 36 */
stevep 0:04a9f72bbca7 37
stevep 0:04a9f72bbca7 38
stevep 0:04a9f72bbca7 39 #ifndef headerfilettmathobject
stevep 0:04a9f72bbca7 40 #define headerfilettmathobject
stevep 0:04a9f72bbca7 41
stevep 0:04a9f72bbca7 42 /*!
stevep 0:04a9f72bbca7 43 \file ttmathobjects.h
stevep 0:04a9f72bbca7 44 \brief Mathematic functions.
stevep 0:04a9f72bbca7 45 */
stevep 0:04a9f72bbca7 46
stevep 0:04a9f72bbca7 47 #include <string>
stevep 0:04a9f72bbca7 48 #include <vector>
stevep 0:04a9f72bbca7 49 #include <list>
stevep 0:04a9f72bbca7 50 #include <map>
stevep 0:04a9f72bbca7 51
stevep 0:04a9f72bbca7 52 #include "ttmathtypes.h"
stevep 0:04a9f72bbca7 53 #include "ttmathmisc.h"
stevep 0:04a9f72bbca7 54
stevep 0:04a9f72bbca7 55
stevep 0:04a9f72bbca7 56 namespace ttmath
stevep 0:04a9f72bbca7 57 {
stevep 0:04a9f72bbca7 58
stevep 0:04a9f72bbca7 59 /*!
stevep 0:04a9f72bbca7 60 objects of this class are used with the mathematical parser
stevep 0:04a9f72bbca7 61 they hold variables or functions defined by a user
stevep 0:04a9f72bbca7 62
stevep 0:04a9f72bbca7 63 each object has its own table in which we're keeping variables or functions
stevep 0:04a9f72bbca7 64 */
stevep 0:04a9f72bbca7 65 class Objects
stevep 0:04a9f72bbca7 66 {
stevep 0:04a9f72bbca7 67 public:
stevep 0:04a9f72bbca7 68
stevep 0:04a9f72bbca7 69
stevep 0:04a9f72bbca7 70 /*!
stevep 0:04a9f72bbca7 71 one item (variable or function)
stevep 0:04a9f72bbca7 72 'items' will be on the table
stevep 0:04a9f72bbca7 73 */
stevep 0:04a9f72bbca7 74 struct Item
stevep 0:04a9f72bbca7 75 {
stevep 0:04a9f72bbca7 76 // name of a variable of a function
stevep 0:04a9f72bbca7 77 // internally we store variables and funcions as std::string (not std::wstring even when wide characters are used)
stevep 0:04a9f72bbca7 78 std::string value;
stevep 0:04a9f72bbca7 79
stevep 0:04a9f72bbca7 80 // number of parameters required by the function
stevep 0:04a9f72bbca7 81 // (if there's a variable this 'param' is ignored)
stevep 0:04a9f72bbca7 82 int param;
stevep 0:04a9f72bbca7 83
stevep 0:04a9f72bbca7 84 Item() {}
stevep 0:04a9f72bbca7 85 Item(const std::string & v, int p) : value(v), param(p) {}
stevep 0:04a9f72bbca7 86 };
stevep 0:04a9f72bbca7 87
stevep 0:04a9f72bbca7 88 // 'Table' is the type of our table
stevep 0:04a9f72bbca7 89 typedef std::map<std::string, Item> Table;
stevep 0:04a9f72bbca7 90 typedef Table::iterator Iterator;
stevep 0:04a9f72bbca7 91 typedef Table::const_iterator CIterator;
stevep 0:04a9f72bbca7 92
stevep 0:04a9f72bbca7 93
stevep 0:04a9f72bbca7 94
stevep 0:04a9f72bbca7 95 /*!
stevep 0:04a9f72bbca7 96 this method returns true if a character 'c' is a character
stevep 0:04a9f72bbca7 97 which can be in a name
stevep 0:04a9f72bbca7 98
stevep 0:04a9f72bbca7 99 if 'can_be_digit' is true that means when the 'c' is a digit this
stevep 0:04a9f72bbca7 100 method returns true otherwise it returns false
stevep 0:04a9f72bbca7 101 */
stevep 0:04a9f72bbca7 102 static bool CorrectCharacter(int c, bool can_be_digit)
stevep 0:04a9f72bbca7 103 {
stevep 0:04a9f72bbca7 104 if( (c>='a' && c<='z') || (c>='A' && c<='Z') )
stevep 0:04a9f72bbca7 105 return true;
stevep 0:04a9f72bbca7 106
stevep 0:04a9f72bbca7 107 if( can_be_digit && ((c>='0' && c<='9') || c=='_') )
stevep 0:04a9f72bbca7 108 return true;
stevep 0:04a9f72bbca7 109
stevep 0:04a9f72bbca7 110 return false;
stevep 0:04a9f72bbca7 111 }
stevep 0:04a9f72bbca7 112
stevep 0:04a9f72bbca7 113
stevep 0:04a9f72bbca7 114 /*!
stevep 0:04a9f72bbca7 115 this method returns true if the name can be as a name of an object
stevep 0:04a9f72bbca7 116 */
stevep 0:04a9f72bbca7 117 template<class string_type>
stevep 0:04a9f72bbca7 118 static bool IsNameCorrect(const string_type & name)
stevep 0:04a9f72bbca7 119 {
stevep 0:04a9f72bbca7 120 if( name.empty() )
stevep 0:04a9f72bbca7 121 return false;
stevep 0:04a9f72bbca7 122
stevep 0:04a9f72bbca7 123 if( !CorrectCharacter(name[0], false) )
stevep 0:04a9f72bbca7 124 return false;
stevep 0:04a9f72bbca7 125
stevep 0:04a9f72bbca7 126 typename string_type::const_iterator i = name.begin();
stevep 0:04a9f72bbca7 127
stevep 0:04a9f72bbca7 128 for(++i ; i!=name.end() ; ++i)
stevep 0:04a9f72bbca7 129 if( !CorrectCharacter(*i, true) )
stevep 0:04a9f72bbca7 130 return false;
stevep 0:04a9f72bbca7 131
stevep 0:04a9f72bbca7 132 return true;
stevep 0:04a9f72bbca7 133 }
stevep 0:04a9f72bbca7 134
stevep 0:04a9f72bbca7 135
stevep 0:04a9f72bbca7 136 /*!
stevep 0:04a9f72bbca7 137 this method returns true if such an object is defined (name exists)
stevep 0:04a9f72bbca7 138 */
stevep 0:04a9f72bbca7 139 bool IsDefined(const std::string & name)
stevep 0:04a9f72bbca7 140 {
stevep 0:04a9f72bbca7 141 Iterator i = table.find(name);
stevep 0:04a9f72bbca7 142
stevep 0:04a9f72bbca7 143 if( i != table.end() )
stevep 0:04a9f72bbca7 144 // we have this object in our table
stevep 0:04a9f72bbca7 145 return true;
stevep 0:04a9f72bbca7 146
stevep 0:04a9f72bbca7 147 return false;
stevep 0:04a9f72bbca7 148 }
stevep 0:04a9f72bbca7 149
stevep 0:04a9f72bbca7 150
stevep 0:04a9f72bbca7 151
stevep 0:04a9f72bbca7 152 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 153
stevep 0:04a9f72bbca7 154 /*!
stevep 0:04a9f72bbca7 155 this method returns true if such an object is defined (name exists)
stevep 0:04a9f72bbca7 156 */
stevep 0:04a9f72bbca7 157 bool IsDefined(const std::wstring & name)
stevep 0:04a9f72bbca7 158 {
stevep 0:04a9f72bbca7 159 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 160 // before calling AssignString() function
stevep 0:04a9f72bbca7 161 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 162 return false;
stevep 0:04a9f72bbca7 163
stevep 0:04a9f72bbca7 164 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 165
stevep 0:04a9f72bbca7 166 return IsDefined(str_tmp1);
stevep 0:04a9f72bbca7 167 }
stevep 0:04a9f72bbca7 168
stevep 0:04a9f72bbca7 169 #endif
stevep 0:04a9f72bbca7 170
stevep 0:04a9f72bbca7 171
stevep 0:04a9f72bbca7 172 /*!
stevep 0:04a9f72bbca7 173 this method adds one object (variable of function) into the table
stevep 0:04a9f72bbca7 174 */
stevep 0:04a9f72bbca7 175 ErrorCode Add(const std::string & name, const std::string & value, int param = 0)
stevep 0:04a9f72bbca7 176 {
stevep 0:04a9f72bbca7 177 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 178 return err_incorrect_name;
stevep 0:04a9f72bbca7 179
stevep 0:04a9f72bbca7 180 Iterator i = table.find(name);
stevep 0:04a9f72bbca7 181
stevep 0:04a9f72bbca7 182 if( i != table.end() )
stevep 0:04a9f72bbca7 183 // we have this object in our table
stevep 0:04a9f72bbca7 184 return err_object_exists;
stevep 0:04a9f72bbca7 185
stevep 0:04a9f72bbca7 186 table.insert( std::make_pair(name, Item(value, param)) );
stevep 0:04a9f72bbca7 187
stevep 0:04a9f72bbca7 188 return err_ok;
stevep 0:04a9f72bbca7 189 }
stevep 0:04a9f72bbca7 190
stevep 0:04a9f72bbca7 191
stevep 0:04a9f72bbca7 192 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 193
stevep 0:04a9f72bbca7 194 /*!
stevep 0:04a9f72bbca7 195 this method adds one object (variable of function) into the table
stevep 0:04a9f72bbca7 196 */
stevep 0:04a9f72bbca7 197 ErrorCode Add(const std::wstring & name, const std::wstring & value, int param = 0)
stevep 0:04a9f72bbca7 198 {
stevep 0:04a9f72bbca7 199 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 200 // before calling AssignString() function
stevep 0:04a9f72bbca7 201 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 202 return err_incorrect_name;
stevep 0:04a9f72bbca7 203
stevep 0:04a9f72bbca7 204 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 205 Misc::AssignString(str_tmp2, value);
stevep 0:04a9f72bbca7 206
stevep 0:04a9f72bbca7 207 return Add(str_tmp1, str_tmp2, param);
stevep 0:04a9f72bbca7 208 }
stevep 0:04a9f72bbca7 209
stevep 0:04a9f72bbca7 210 #endif
stevep 0:04a9f72bbca7 211
stevep 0:04a9f72bbca7 212
stevep 0:04a9f72bbca7 213 /*!
stevep 0:04a9f72bbca7 214 this method returns 'true' if the table is empty
stevep 0:04a9f72bbca7 215 */
stevep 0:04a9f72bbca7 216 bool Empty() const
stevep 0:04a9f72bbca7 217 {
stevep 0:04a9f72bbca7 218 return table.empty();
stevep 0:04a9f72bbca7 219 }
stevep 0:04a9f72bbca7 220
stevep 0:04a9f72bbca7 221
stevep 0:04a9f72bbca7 222 /*!
stevep 0:04a9f72bbca7 223 this method clears the table
stevep 0:04a9f72bbca7 224 */
stevep 0:04a9f72bbca7 225 void Clear()
stevep 0:04a9f72bbca7 226 {
stevep 0:04a9f72bbca7 227 return table.clear();
stevep 0:04a9f72bbca7 228 }
stevep 0:04a9f72bbca7 229
stevep 0:04a9f72bbca7 230
stevep 0:04a9f72bbca7 231 /*!
stevep 0:04a9f72bbca7 232 this method returns 'const_iterator' on the first item on the table
stevep 0:04a9f72bbca7 233 */
stevep 0:04a9f72bbca7 234 CIterator Begin() const
stevep 0:04a9f72bbca7 235 {
stevep 0:04a9f72bbca7 236 return table.begin();
stevep 0:04a9f72bbca7 237 }
stevep 0:04a9f72bbca7 238
stevep 0:04a9f72bbca7 239
stevep 0:04a9f72bbca7 240 /*!
stevep 0:04a9f72bbca7 241 this method returns 'const_iterator' pointing at the space after last item
stevep 0:04a9f72bbca7 242 (returns table.end())
stevep 0:04a9f72bbca7 243 */
stevep 0:04a9f72bbca7 244 CIterator End() const
stevep 0:04a9f72bbca7 245 {
stevep 0:04a9f72bbca7 246 return table.end();
stevep 0:04a9f72bbca7 247 }
stevep 0:04a9f72bbca7 248
stevep 0:04a9f72bbca7 249
stevep 0:04a9f72bbca7 250 /*!
stevep 0:04a9f72bbca7 251 this method changes the value and the number of parameters for a specific object
stevep 0:04a9f72bbca7 252 */
stevep 0:04a9f72bbca7 253 ErrorCode EditValue(const std::string & name, const std::string & value, int param = 0)
stevep 0:04a9f72bbca7 254 {
stevep 0:04a9f72bbca7 255 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 256 return err_incorrect_name;
stevep 0:04a9f72bbca7 257
stevep 0:04a9f72bbca7 258 Iterator i = table.find(name);
stevep 0:04a9f72bbca7 259
stevep 0:04a9f72bbca7 260 if( i == table.end() )
stevep 0:04a9f72bbca7 261 return err_unknown_object;
stevep 0:04a9f72bbca7 262
stevep 0:04a9f72bbca7 263 i->second.value = value;
stevep 0:04a9f72bbca7 264 i->second.param = param;
stevep 0:04a9f72bbca7 265
stevep 0:04a9f72bbca7 266 return err_ok;
stevep 0:04a9f72bbca7 267 }
stevep 0:04a9f72bbca7 268
stevep 0:04a9f72bbca7 269
stevep 0:04a9f72bbca7 270 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 271
stevep 0:04a9f72bbca7 272
stevep 0:04a9f72bbca7 273 /*!
stevep 0:04a9f72bbca7 274 this method changes the value and the number of parameters for a specific object
stevep 0:04a9f72bbca7 275 */
stevep 0:04a9f72bbca7 276 ErrorCode EditValue(const std::wstring & name, const std::wstring & value, int param = 0)
stevep 0:04a9f72bbca7 277 {
stevep 0:04a9f72bbca7 278 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 279 // before calling AssignString() function
stevep 0:04a9f72bbca7 280 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 281 return err_incorrect_name;
stevep 0:04a9f72bbca7 282
stevep 0:04a9f72bbca7 283 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 284 Misc::AssignString(str_tmp2, value);
stevep 0:04a9f72bbca7 285
stevep 0:04a9f72bbca7 286 return EditValue(str_tmp1, str_tmp2, param);
stevep 0:04a9f72bbca7 287 }
stevep 0:04a9f72bbca7 288
stevep 0:04a9f72bbca7 289 #endif
stevep 0:04a9f72bbca7 290
stevep 0:04a9f72bbca7 291
stevep 0:04a9f72bbca7 292 /*!
stevep 0:04a9f72bbca7 293 this method changes the name of a specific object
stevep 0:04a9f72bbca7 294 */
stevep 0:04a9f72bbca7 295 ErrorCode EditName(const std::string & old_name, const std::string & new_name)
stevep 0:04a9f72bbca7 296 {
stevep 0:04a9f72bbca7 297 if( !IsNameCorrect(old_name) || !IsNameCorrect(new_name) )
stevep 0:04a9f72bbca7 298 return err_incorrect_name;
stevep 0:04a9f72bbca7 299
stevep 0:04a9f72bbca7 300 Iterator old_i = table.find(old_name);
stevep 0:04a9f72bbca7 301 if( old_i == table.end() )
stevep 0:04a9f72bbca7 302 return err_unknown_object;
stevep 0:04a9f72bbca7 303
stevep 0:04a9f72bbca7 304 if( old_name == new_name )
stevep 0:04a9f72bbca7 305 // the new name is the same as the old one
stevep 0:04a9f72bbca7 306 // we treat it as a normal situation
stevep 0:04a9f72bbca7 307 return err_ok;
stevep 0:04a9f72bbca7 308
stevep 0:04a9f72bbca7 309 ErrorCode err = Add(new_name, old_i->second.value, old_i->second.param);
stevep 0:04a9f72bbca7 310
stevep 0:04a9f72bbca7 311 if( err == err_ok )
stevep 0:04a9f72bbca7 312 {
stevep 0:04a9f72bbca7 313 old_i = table.find(old_name);
stevep 0:04a9f72bbca7 314 TTMATH_ASSERT( old_i != table.end() )
stevep 0:04a9f72bbca7 315
stevep 0:04a9f72bbca7 316 table.erase(old_i);
stevep 0:04a9f72bbca7 317 }
stevep 0:04a9f72bbca7 318
stevep 0:04a9f72bbca7 319 return err;
stevep 0:04a9f72bbca7 320 }
stevep 0:04a9f72bbca7 321
stevep 0:04a9f72bbca7 322
stevep 0:04a9f72bbca7 323
stevep 0:04a9f72bbca7 324 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 325
stevep 0:04a9f72bbca7 326
stevep 0:04a9f72bbca7 327 /*!
stevep 0:04a9f72bbca7 328 this method changes the name of a specific object
stevep 0:04a9f72bbca7 329 */
stevep 0:04a9f72bbca7 330 ErrorCode EditName(const std::wstring & old_name, const std::wstring & new_name)
stevep 0:04a9f72bbca7 331 {
stevep 0:04a9f72bbca7 332 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 333 // before calling AssignString() function
stevep 0:04a9f72bbca7 334 if( !IsNameCorrect(old_name) || !IsNameCorrect(new_name) )
stevep 0:04a9f72bbca7 335 return err_incorrect_name;
stevep 0:04a9f72bbca7 336
stevep 0:04a9f72bbca7 337 Misc::AssignString(str_tmp1, old_name);
stevep 0:04a9f72bbca7 338 Misc::AssignString(str_tmp2, new_name);
stevep 0:04a9f72bbca7 339
stevep 0:04a9f72bbca7 340 return EditName(str_tmp1, str_tmp2);
stevep 0:04a9f72bbca7 341 }
stevep 0:04a9f72bbca7 342
stevep 0:04a9f72bbca7 343 #endif
stevep 0:04a9f72bbca7 344
stevep 0:04a9f72bbca7 345
stevep 0:04a9f72bbca7 346 /*!
stevep 0:04a9f72bbca7 347 this method deletes an object
stevep 0:04a9f72bbca7 348 */
stevep 0:04a9f72bbca7 349 ErrorCode Delete(const std::string & name)
stevep 0:04a9f72bbca7 350 {
stevep 0:04a9f72bbca7 351 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 352 return err_incorrect_name;
stevep 0:04a9f72bbca7 353
stevep 0:04a9f72bbca7 354 Iterator i = table.find(name);
stevep 0:04a9f72bbca7 355
stevep 0:04a9f72bbca7 356 if( i == table.end() )
stevep 0:04a9f72bbca7 357 return err_unknown_object;
stevep 0:04a9f72bbca7 358
stevep 0:04a9f72bbca7 359 table.erase( i );
stevep 0:04a9f72bbca7 360
stevep 0:04a9f72bbca7 361 return err_ok;
stevep 0:04a9f72bbca7 362 }
stevep 0:04a9f72bbca7 363
stevep 0:04a9f72bbca7 364
stevep 0:04a9f72bbca7 365 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 366
stevep 0:04a9f72bbca7 367
stevep 0:04a9f72bbca7 368 /*!
stevep 0:04a9f72bbca7 369 this method deletes an object
stevep 0:04a9f72bbca7 370 */
stevep 0:04a9f72bbca7 371 ErrorCode Delete(const std::wstring & name)
stevep 0:04a9f72bbca7 372 {
stevep 0:04a9f72bbca7 373 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 374 // before calling AssignString() function
stevep 0:04a9f72bbca7 375 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 376 return err_incorrect_name;
stevep 0:04a9f72bbca7 377
stevep 0:04a9f72bbca7 378 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 379
stevep 0:04a9f72bbca7 380 return Delete(str_tmp1);
stevep 0:04a9f72bbca7 381 }
stevep 0:04a9f72bbca7 382
stevep 0:04a9f72bbca7 383 #endif
stevep 0:04a9f72bbca7 384
stevep 0:04a9f72bbca7 385
stevep 0:04a9f72bbca7 386 /*!
stevep 0:04a9f72bbca7 387 this method gets the value of a specific object
stevep 0:04a9f72bbca7 388 */
stevep 0:04a9f72bbca7 389 ErrorCode GetValue(const std::string & name, std::string & value) const
stevep 0:04a9f72bbca7 390 {
stevep 0:04a9f72bbca7 391 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 392 return err_incorrect_name;
stevep 0:04a9f72bbca7 393
stevep 0:04a9f72bbca7 394 CIterator i = table.find(name);
stevep 0:04a9f72bbca7 395
stevep 0:04a9f72bbca7 396 if( i == table.end() )
stevep 0:04a9f72bbca7 397 {
stevep 0:04a9f72bbca7 398 value.clear();
stevep 0:04a9f72bbca7 399 return err_unknown_object;
stevep 0:04a9f72bbca7 400 }
stevep 0:04a9f72bbca7 401
stevep 0:04a9f72bbca7 402 value = i->second.value;
stevep 0:04a9f72bbca7 403
stevep 0:04a9f72bbca7 404 return err_ok;
stevep 0:04a9f72bbca7 405 }
stevep 0:04a9f72bbca7 406
stevep 0:04a9f72bbca7 407
stevep 0:04a9f72bbca7 408 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 409
stevep 0:04a9f72bbca7 410 /*!
stevep 0:04a9f72bbca7 411 this method gets the value of a specific object
stevep 0:04a9f72bbca7 412 */
stevep 0:04a9f72bbca7 413 ErrorCode GetValue(const std::wstring & name, std::wstring & value)
stevep 0:04a9f72bbca7 414 {
stevep 0:04a9f72bbca7 415 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 416 // before calling AssignString() function
stevep 0:04a9f72bbca7 417 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 418 return err_incorrect_name;
stevep 0:04a9f72bbca7 419
stevep 0:04a9f72bbca7 420 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 421 ErrorCode err = GetValue(str_tmp1, str_tmp2);
stevep 0:04a9f72bbca7 422 Misc::AssignString(value, str_tmp2);
stevep 0:04a9f72bbca7 423
stevep 0:04a9f72bbca7 424 return err;
stevep 0:04a9f72bbca7 425 }
stevep 0:04a9f72bbca7 426
stevep 0:04a9f72bbca7 427 #endif
stevep 0:04a9f72bbca7 428
stevep 0:04a9f72bbca7 429
stevep 0:04a9f72bbca7 430 /*!
stevep 0:04a9f72bbca7 431 this method gets the value of a specific object
stevep 0:04a9f72bbca7 432 (this version is used for not copying the whole string)
stevep 0:04a9f72bbca7 433 */
stevep 0:04a9f72bbca7 434 ErrorCode GetValue(const std::string & name, const char ** value) const
stevep 0:04a9f72bbca7 435 {
stevep 0:04a9f72bbca7 436 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 437 return err_incorrect_name;
stevep 0:04a9f72bbca7 438
stevep 0:04a9f72bbca7 439 CIterator i = table.find(name);
stevep 0:04a9f72bbca7 440
stevep 0:04a9f72bbca7 441 if( i == table.end() )
stevep 0:04a9f72bbca7 442 {
stevep 0:04a9f72bbca7 443 *value = 0;
stevep 0:04a9f72bbca7 444 return err_unknown_object;
stevep 0:04a9f72bbca7 445 }
stevep 0:04a9f72bbca7 446
stevep 0:04a9f72bbca7 447 *value = i->second.value.c_str();
stevep 0:04a9f72bbca7 448
stevep 0:04a9f72bbca7 449 return err_ok;
stevep 0:04a9f72bbca7 450 }
stevep 0:04a9f72bbca7 451
stevep 0:04a9f72bbca7 452
stevep 0:04a9f72bbca7 453 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 454
stevep 0:04a9f72bbca7 455 /*!
stevep 0:04a9f72bbca7 456 this method gets the value of a specific object
stevep 0:04a9f72bbca7 457 (this version is used for not copying the whole string)
stevep 0:04a9f72bbca7 458 */
stevep 0:04a9f72bbca7 459 ErrorCode GetValue(const std::wstring & name, const char ** value)
stevep 0:04a9f72bbca7 460 {
stevep 0:04a9f72bbca7 461 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 462 // before calling AssignString() function
stevep 0:04a9f72bbca7 463 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 464 return err_incorrect_name;
stevep 0:04a9f72bbca7 465
stevep 0:04a9f72bbca7 466 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 467
stevep 0:04a9f72bbca7 468 return GetValue(str_tmp1, value);
stevep 0:04a9f72bbca7 469 }
stevep 0:04a9f72bbca7 470
stevep 0:04a9f72bbca7 471 #endif
stevep 0:04a9f72bbca7 472
stevep 0:04a9f72bbca7 473
stevep 0:04a9f72bbca7 474 /*!
stevep 0:04a9f72bbca7 475 this method gets the value and the number of parameters
stevep 0:04a9f72bbca7 476 of a specific object
stevep 0:04a9f72bbca7 477 */
stevep 0:04a9f72bbca7 478 ErrorCode GetValueAndParam(const std::string & name, std::string & value, int * param) const
stevep 0:04a9f72bbca7 479 {
stevep 0:04a9f72bbca7 480 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 481 return err_incorrect_name;
stevep 0:04a9f72bbca7 482
stevep 0:04a9f72bbca7 483 CIterator i = table.find(name);
stevep 0:04a9f72bbca7 484
stevep 0:04a9f72bbca7 485 if( i == table.end() )
stevep 0:04a9f72bbca7 486 {
stevep 0:04a9f72bbca7 487 value.empty();
stevep 0:04a9f72bbca7 488 *param = 0;
stevep 0:04a9f72bbca7 489 return err_unknown_object;
stevep 0:04a9f72bbca7 490 }
stevep 0:04a9f72bbca7 491
stevep 0:04a9f72bbca7 492 value = i->second.value;
stevep 0:04a9f72bbca7 493 *param = i->second.param;
stevep 0:04a9f72bbca7 494
stevep 0:04a9f72bbca7 495 return err_ok;
stevep 0:04a9f72bbca7 496 }
stevep 0:04a9f72bbca7 497
stevep 0:04a9f72bbca7 498
stevep 0:04a9f72bbca7 499 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 500
stevep 0:04a9f72bbca7 501 /*!
stevep 0:04a9f72bbca7 502 this method gets the value and the number of parameters
stevep 0:04a9f72bbca7 503 of a specific object
stevep 0:04a9f72bbca7 504 */
stevep 0:04a9f72bbca7 505 ErrorCode GetValueAndParam(const std::wstring & name, std::wstring & value, int * param)
stevep 0:04a9f72bbca7 506 {
stevep 0:04a9f72bbca7 507 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 508 // before calling AssignString() function
stevep 0:04a9f72bbca7 509 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 510 return err_incorrect_name;
stevep 0:04a9f72bbca7 511
stevep 0:04a9f72bbca7 512 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 513 ErrorCode err = GetValueAndParam(str_tmp1, str_tmp2, param);
stevep 0:04a9f72bbca7 514 Misc::AssignString(value, str_tmp2);
stevep 0:04a9f72bbca7 515
stevep 0:04a9f72bbca7 516 return err;
stevep 0:04a9f72bbca7 517 }
stevep 0:04a9f72bbca7 518
stevep 0:04a9f72bbca7 519 #endif
stevep 0:04a9f72bbca7 520
stevep 0:04a9f72bbca7 521
stevep 0:04a9f72bbca7 522 /*!
stevep 0:04a9f72bbca7 523 this method sets the value and the number of parameters
stevep 0:04a9f72bbca7 524 of a specific object
stevep 0:04a9f72bbca7 525 (this version is used for not copying the whole string)
stevep 0:04a9f72bbca7 526 */
stevep 0:04a9f72bbca7 527 ErrorCode GetValueAndParam(const std::string & name, const char ** value, int * param) const
stevep 0:04a9f72bbca7 528 {
stevep 0:04a9f72bbca7 529 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 530 return err_incorrect_name;
stevep 0:04a9f72bbca7 531
stevep 0:04a9f72bbca7 532 CIterator i = table.find(name);
stevep 0:04a9f72bbca7 533
stevep 0:04a9f72bbca7 534 if( i == table.end() )
stevep 0:04a9f72bbca7 535 {
stevep 0:04a9f72bbca7 536 *value = 0;
stevep 0:04a9f72bbca7 537 *param = 0;
stevep 0:04a9f72bbca7 538 return err_unknown_object;
stevep 0:04a9f72bbca7 539 }
stevep 0:04a9f72bbca7 540
stevep 0:04a9f72bbca7 541 *value = i->second.value.c_str();
stevep 0:04a9f72bbca7 542 *param = i->second.param;
stevep 0:04a9f72bbca7 543
stevep 0:04a9f72bbca7 544 return err_ok;
stevep 0:04a9f72bbca7 545 }
stevep 0:04a9f72bbca7 546
stevep 0:04a9f72bbca7 547
stevep 0:04a9f72bbca7 548 #ifndef TTMATH_DONT_USE_WCHAR
stevep 0:04a9f72bbca7 549
stevep 0:04a9f72bbca7 550
stevep 0:04a9f72bbca7 551 /*!
stevep 0:04a9f72bbca7 552 this method sets the value and the number of parameters
stevep 0:04a9f72bbca7 553 of a specific object
stevep 0:04a9f72bbca7 554 (this version is used for not copying the whole string
stevep 0:04a9f72bbca7 555 but in fact we make one copying during AssignString())
stevep 0:04a9f72bbca7 556 */
stevep 0:04a9f72bbca7 557 ErrorCode GetValueAndParam(const std::wstring & name, const char ** value, int * param)
stevep 0:04a9f72bbca7 558 {
stevep 0:04a9f72bbca7 559 // we should check whether the name (in wide characters) are correct
stevep 0:04a9f72bbca7 560 // before calling AssignString() function
stevep 0:04a9f72bbca7 561 if( !IsNameCorrect(name) )
stevep 0:04a9f72bbca7 562 return err_incorrect_name;
stevep 0:04a9f72bbca7 563
stevep 0:04a9f72bbca7 564 Misc::AssignString(str_tmp1, name);
stevep 0:04a9f72bbca7 565
stevep 0:04a9f72bbca7 566 return GetValueAndParam(str_tmp1, value, param);
stevep 0:04a9f72bbca7 567 }
stevep 0:04a9f72bbca7 568
stevep 0:04a9f72bbca7 569
stevep 0:04a9f72bbca7 570 #endif
stevep 0:04a9f72bbca7 571
stevep 0:04a9f72bbca7 572
stevep 0:04a9f72bbca7 573 /*!
stevep 0:04a9f72bbca7 574 this method returns a pointer into the table
stevep 0:04a9f72bbca7 575 */
stevep 0:04a9f72bbca7 576 Table * GetTable()
stevep 0:04a9f72bbca7 577 {
stevep 0:04a9f72bbca7 578 return &table;
stevep 0:04a9f72bbca7 579 }
stevep 0:04a9f72bbca7 580
stevep 0:04a9f72bbca7 581
stevep 0:04a9f72bbca7 582 private:
stevep 0:04a9f72bbca7 583
stevep 0:04a9f72bbca7 584 Table table;
stevep 0:04a9f72bbca7 585 std::string str_tmp1, str_tmp2;
stevep 0:04a9f72bbca7 586
stevep 0:04a9f72bbca7 587 }; // end of class Objects
stevep 0:04a9f72bbca7 588
stevep 0:04a9f72bbca7 589
stevep 0:04a9f72bbca7 590
stevep 0:04a9f72bbca7 591
stevep 0:04a9f72bbca7 592
stevep 0:04a9f72bbca7 593
stevep 0:04a9f72bbca7 594
stevep 0:04a9f72bbca7 595 /*!
stevep 0:04a9f72bbca7 596 objects of the class History are used to keep values in functions
stevep 0:04a9f72bbca7 597 which take a lot of time during calculating, for instance in the
stevep 0:04a9f72bbca7 598 function Factorial(x)
stevep 0:04a9f72bbca7 599
stevep 0:04a9f72bbca7 600 it means that when we're calculating e.g. Factorial(1000) and the
stevep 0:04a9f72bbca7 601 Factorial finds that we have calculated it before, the value (result)
stevep 0:04a9f72bbca7 602 is taken from the history
stevep 0:04a9f72bbca7 603 */
stevep 0:04a9f72bbca7 604 template<class ValueType>
stevep 0:04a9f72bbca7 605 class History
stevep 0:04a9f72bbca7 606 {
stevep 0:04a9f72bbca7 607 /*!
stevep 0:04a9f72bbca7 608 one item in the History's object holds a key, a value for the key
stevep 0:04a9f72bbca7 609 and a corresponding error code
stevep 0:04a9f72bbca7 610 */
stevep 0:04a9f72bbca7 611 struct Item
stevep 0:04a9f72bbca7 612 {
stevep 0:04a9f72bbca7 613 ValueType key, value;
stevep 0:04a9f72bbca7 614 ErrorCode err;
stevep 0:04a9f72bbca7 615 };
stevep 0:04a9f72bbca7 616
stevep 0:04a9f72bbca7 617
stevep 0:04a9f72bbca7 618 /*!
stevep 0:04a9f72bbca7 619 we use std::list for simply deleting the first item
stevep 0:04a9f72bbca7 620 but because we're searching through the whole container
stevep 0:04a9f72bbca7 621 (in the method Get) the container should not be too big
stevep 0:04a9f72bbca7 622 (linear time of searching)
stevep 0:04a9f72bbca7 623 */
stevep 0:04a9f72bbca7 624 typedef std::list<Item> buffer_type;
stevep 0:04a9f72bbca7 625 buffer_type buffer;
stevep 0:04a9f72bbca7 626 typename buffer_type::size_type buffer_max_size;
stevep 0:04a9f72bbca7 627
stevep 0:04a9f72bbca7 628 public:
stevep 0:04a9f72bbca7 629
stevep 0:04a9f72bbca7 630 /*!
stevep 0:04a9f72bbca7 631 default constructor
stevep 0:04a9f72bbca7 632 default max size of the History's container is 15 items
stevep 0:04a9f72bbca7 633 */
stevep 0:04a9f72bbca7 634 History()
stevep 0:04a9f72bbca7 635 {
stevep 0:04a9f72bbca7 636 buffer_max_size = 15;
stevep 0:04a9f72bbca7 637 }
stevep 0:04a9f72bbca7 638
stevep 0:04a9f72bbca7 639
stevep 0:04a9f72bbca7 640 /*!
stevep 0:04a9f72bbca7 641 a constructor which takes another value of the max size
stevep 0:04a9f72bbca7 642 of the History's container
stevep 0:04a9f72bbca7 643 */
stevep 0:04a9f72bbca7 644 History(typename buffer_type::size_type new_size)
stevep 0:04a9f72bbca7 645 {
stevep 0:04a9f72bbca7 646 buffer_max_size = new_size;
stevep 0:04a9f72bbca7 647 }
stevep 0:04a9f72bbca7 648
stevep 0:04a9f72bbca7 649
stevep 0:04a9f72bbca7 650 /*!
stevep 0:04a9f72bbca7 651 this method adds one item into the History
stevep 0:04a9f72bbca7 652 if the size of the container is greater than buffer_max_size
stevep 0:04a9f72bbca7 653 the first item will be removed
stevep 0:04a9f72bbca7 654 */
stevep 0:04a9f72bbca7 655 void Add(const ValueType & key, const ValueType & value, ErrorCode err)
stevep 0:04a9f72bbca7 656 {
stevep 0:04a9f72bbca7 657 Item item;
stevep 0:04a9f72bbca7 658 item.key = key;
stevep 0:04a9f72bbca7 659 item.value = value;
stevep 0:04a9f72bbca7 660 item.err = err;
stevep 0:04a9f72bbca7 661
stevep 0:04a9f72bbca7 662 buffer.insert( buffer.end(), item );
stevep 0:04a9f72bbca7 663
stevep 0:04a9f72bbca7 664 if( buffer.size() > buffer_max_size )
stevep 0:04a9f72bbca7 665 buffer.erase(buffer.begin());
stevep 0:04a9f72bbca7 666 }
stevep 0:04a9f72bbca7 667
stevep 0:04a9f72bbca7 668
stevep 0:04a9f72bbca7 669 /*!
stevep 0:04a9f72bbca7 670 this method checks whether we have an item which has the key equal 'key'
stevep 0:04a9f72bbca7 671
stevep 0:04a9f72bbca7 672 if there's such item the method sets the 'value' and the 'err'
stevep 0:04a9f72bbca7 673 and returns true otherwise it returns false and 'value' and 'err'
stevep 0:04a9f72bbca7 674 remain unchanged
stevep 0:04a9f72bbca7 675 */
stevep 0:04a9f72bbca7 676 bool Get(const ValueType & key, ValueType & value, ErrorCode & err)
stevep 0:04a9f72bbca7 677 {
stevep 0:04a9f72bbca7 678 typename buffer_type::iterator i = buffer.begin();
stevep 0:04a9f72bbca7 679
stevep 0:04a9f72bbca7 680 for( ; i != buffer.end() ; ++i )
stevep 0:04a9f72bbca7 681 {
stevep 0:04a9f72bbca7 682 if( i->key == key )
stevep 0:04a9f72bbca7 683 {
stevep 0:04a9f72bbca7 684 value = i->value;
stevep 0:04a9f72bbca7 685 err = i->err;
stevep 0:04a9f72bbca7 686 return true;
stevep 0:04a9f72bbca7 687 }
stevep 0:04a9f72bbca7 688 }
stevep 0:04a9f72bbca7 689
stevep 0:04a9f72bbca7 690 return false;
stevep 0:04a9f72bbca7 691 }
stevep 0:04a9f72bbca7 692
stevep 0:04a9f72bbca7 693
stevep 0:04a9f72bbca7 694 /*!
stevep 0:04a9f72bbca7 695 this methods deletes an item
stevep 0:04a9f72bbca7 696
stevep 0:04a9f72bbca7 697 we assume that there is only one item with the 'key'
stevep 0:04a9f72bbca7 698 (this methods removes the first one)
stevep 0:04a9f72bbca7 699 */
stevep 0:04a9f72bbca7 700 bool Remove(const ValueType & key)
stevep 0:04a9f72bbca7 701 {
stevep 0:04a9f72bbca7 702 typename buffer_type::iterator i = buffer.begin();
stevep 0:04a9f72bbca7 703
stevep 0:04a9f72bbca7 704 for( ; i != buffer.end() ; ++i )
stevep 0:04a9f72bbca7 705 {
stevep 0:04a9f72bbca7 706 if( i->key == key )
stevep 0:04a9f72bbca7 707 {
stevep 0:04a9f72bbca7 708 buffer.erase(i);
stevep 0:04a9f72bbca7 709 return true;
stevep 0:04a9f72bbca7 710 }
stevep 0:04a9f72bbca7 711 }
stevep 0:04a9f72bbca7 712
stevep 0:04a9f72bbca7 713 return false;
stevep 0:04a9f72bbca7 714 }
stevep 0:04a9f72bbca7 715
stevep 0:04a9f72bbca7 716
stevep 0:04a9f72bbca7 717 }; // end of class History
stevep 0:04a9f72bbca7 718
stevep 0:04a9f72bbca7 719
stevep 0:04a9f72bbca7 720
stevep 0:04a9f72bbca7 721 /*!
stevep 0:04a9f72bbca7 722 this is an auxiliary class used when calculating Gamma() or Factorial()
stevep 0:04a9f72bbca7 723
stevep 0:04a9f72bbca7 724 in multithreaded environment you can provide an object of this class to
stevep 0:04a9f72bbca7 725 the Gamma() or Factorial() function, e.g;
stevep 0:04a9f72bbca7 726 typedef Big<1, 3> MyBig;
stevep 0:04a9f72bbca7 727 MyBig x = 123456;
stevep 0:04a9f72bbca7 728 CGamma<MyBig> cgamma;
stevep 0:04a9f72bbca7 729 std::cout << Gamma(x, cgamma);
stevep 0:04a9f72bbca7 730 each thread should have its own CGamma<> object
stevep 0:04a9f72bbca7 731
stevep 0:04a9f72bbca7 732 in a single-thread environment a CGamma<> object is a static variable
stevep 0:04a9f72bbca7 733 in a second version of Gamma() and you don't have to explicitly use it, e.g.
stevep 0:04a9f72bbca7 734 typedef Big<1, 3> MyBig;
stevep 0:04a9f72bbca7 735 MyBig x = 123456;
stevep 0:04a9f72bbca7 736 std::cout << Gamma(x);
stevep 0:04a9f72bbca7 737 */
stevep 0:04a9f72bbca7 738 template<class ValueType>
stevep 0:04a9f72bbca7 739 struct CGamma
stevep 0:04a9f72bbca7 740 {
stevep 0:04a9f72bbca7 741 /*!
stevep 0:04a9f72bbca7 742 this table holds factorials
stevep 0:04a9f72bbca7 743 1
stevep 0:04a9f72bbca7 744 1
stevep 0:04a9f72bbca7 745 2
stevep 0:04a9f72bbca7 746 6
stevep 0:04a9f72bbca7 747 24
stevep 0:04a9f72bbca7 748 120
stevep 0:04a9f72bbca7 749 720
stevep 0:04a9f72bbca7 750 .......
stevep 0:04a9f72bbca7 751 */
stevep 0:04a9f72bbca7 752 std::vector<ValueType> fact;
stevep 0:04a9f72bbca7 753
stevep 0:04a9f72bbca7 754
stevep 0:04a9f72bbca7 755 /*!
stevep 0:04a9f72bbca7 756 this table holds Bernoulli numbers
stevep 0:04a9f72bbca7 757 1
stevep 0:04a9f72bbca7 758 -0.5
stevep 0:04a9f72bbca7 759 0.166666666666666666666666667
stevep 0:04a9f72bbca7 760 0
stevep 0:04a9f72bbca7 761 -0.0333333333333333333333333333
stevep 0:04a9f72bbca7 762 0
stevep 0:04a9f72bbca7 763 0.0238095238095238095238095238
stevep 0:04a9f72bbca7 764 0
stevep 0:04a9f72bbca7 765 -0.0333333333333333333333333333
stevep 0:04a9f72bbca7 766 0
stevep 0:04a9f72bbca7 767 0.075757575757575757575757576
stevep 0:04a9f72bbca7 768 .....
stevep 0:04a9f72bbca7 769 */
stevep 0:04a9f72bbca7 770 std::vector<ValueType> bern;
stevep 0:04a9f72bbca7 771
stevep 0:04a9f72bbca7 772
stevep 0:04a9f72bbca7 773 /*!
stevep 0:04a9f72bbca7 774 here we store some calculated values
stevep 0:04a9f72bbca7 775 (this is for speeding up, if the next argument of Gamma() or Factorial()
stevep 0:04a9f72bbca7 776 is in the 'history' then the result we are not calculating but simply
stevep 0:04a9f72bbca7 777 return from the 'history' object)
stevep 0:04a9f72bbca7 778 */
stevep 0:04a9f72bbca7 779 History<ValueType> history;
stevep 0:04a9f72bbca7 780
stevep 0:04a9f72bbca7 781
stevep 0:04a9f72bbca7 782 /*!
stevep 0:04a9f72bbca7 783 this method prepares some coefficients: factorials and Bernoulli numbers
stevep 0:04a9f72bbca7 784 stored in 'fact' and 'bern' objects
stevep 0:04a9f72bbca7 785
stevep 0:04a9f72bbca7 786 how many values should be depends on the size of the mantissa - if
stevep 0:04a9f72bbca7 787 the mantissa is larger then we must calculate more values
stevep 0:04a9f72bbca7 788 for a mantissa which consists of 256 bits (8 words on a 32bit platform)
stevep 0:04a9f72bbca7 789 we have to calculate about 30 values (the size of fact and bern will be 30),
stevep 0:04a9f72bbca7 790 and for a 2048 bits mantissa we have to calculate 306 coefficients
stevep 0:04a9f72bbca7 791
stevep 0:04a9f72bbca7 792 you don't have to call this method, these coefficients will be automatically calculated
stevep 0:04a9f72bbca7 793 when they are needed
stevep 0:04a9f72bbca7 794
stevep 0:04a9f72bbca7 795 you must note that calculating these coefficients is a little time-consuming operation,
stevep 0:04a9f72bbca7 796 (especially when the mantissa is large) and first call to Gamma() or Factorial()
stevep 0:04a9f72bbca7 797 can take more time than next calls, and in the end this is the point when InitAll()
stevep 0:04a9f72bbca7 798 comes in handy: you can call this method somewhere at the beginning of your program
stevep 0:04a9f72bbca7 799 */
stevep 0:04a9f72bbca7 800 void InitAll();
stevep 0:04a9f72bbca7 801 // definition is in ttmath.h
stevep 0:04a9f72bbca7 802 };
stevep 0:04a9f72bbca7 803
stevep 0:04a9f72bbca7 804
stevep 0:04a9f72bbca7 805
stevep 0:04a9f72bbca7 806
stevep 0:04a9f72bbca7 807 } // namespace
stevep 0:04a9f72bbca7 808
stevep 0:04a9f72bbca7 809 #endif
stevep 0:04a9f72bbca7 810