added: DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
RadToDeg(rad), Ceil(x), Floor(x), Sqrt(x), Sinh(x), Cosh(x), Tanh(x) /Tgh(x)/, Coth(x) /Ctgh(x)/ changed: class Objects in ttmathobjects.h has been completely rewritten, we can change the names of user-defined variables or functions, and the names are case-sensitive now added: class History which is used in functions which take a lot of time during calculating e.g. Factorial(x) added: Tg(x) a wrapper for Tan(x) changed: CTan(x) is Cot(x) now added: Ctg(x) a wrapper for Cot(x) added: ATg(x) a wrapper for ATan(x) changed: ACTan(x) is ACot(x) now added: ACtg(x) a wrapper for ACot(x) added: UInt::PrintTable() (for debugging etc.) changed: the methods Big::SetPi() Big::SetE() and Big::SetLn2() have been rewritten, now they have 128 32bit words (it's about 1232 valid decimal digits) fixed: previous values from Big::SetPi() Big::SetE() and Big::SetLn2() were not too much accurate (last 2-3 words were wrong) added: Big::SetLn10() (128 32bit words as well) added: macro: TTMATH_BUILTIN_VARIABLES_SIZE which is equal 128u on 32bit platforms and 64ul on 64bit platforms (128/2=64) added: macros: TTMATH_PLATFORM32 and TTMATH_PLATFORM64 changed: a small optimisation in UInt::Mul2Big() added: at the end of ttmath.h: #include "ttmathparser.h" this is for convenience for a programmer, he can only use #include with ttmath.h even if he uses the parser added: to samples: big.cpp, parser.cpp fixed: constructor Big::Big(uint) - it was wrong because it was using the method Big::FromInt(sint) which could produce wrong values (if the 'uint' couldn't correctly be casted into the 'sint') added: Big::FromUInt(uint) changed: Big::FromInt(sint), Big::SetOne(), renamed Big::SetDotOne() into Big::Set05() (they are a little faster now) added: Big::operator=(uint) changed: in 64bit mode: constructor: Big::Big(int) added: in 64bit mode: constructor: Big::Big(unsigned int), operators: Big::operator=(signed int) and Big::operator=(unsigned int) (these operators and the constructor take a 32bit value) deleted: the word 'virtual' from destructors: UInt, Int, Big (types in this library are not projected to be base-classes for another ones derived from them) changed: UInt::operator=(uint), UInt::UInt(uint), Int::operator=(sint), Int::Int(sint) added: UInt::FromUInt(uint), UInt::operator=(sint), UInt::UInt(sint), Int::FromInt(sint), Int::operator=(uint), Int::Int(uint), Int::operator==(const Int<>&), Int::operator!=(const Int<>&) added: in 64bit mode: UInt::operator=(unsigned int), UInt::UInt(unsigned int), UInt::operator=(signed int), UInt::UInt(signed int) (these operators and the constructors take a 32bit value) added: in 64bit mode: Int::operator=(signed int), Int::Int(signed int), Int::operator=(unsigned int), Int::Int(unsigned int) (these operators and the constructors take a 32bit value) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@25 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -8,7 +8,7 @@ CFLAGS = -Wall -pedantic -s -O2 -I..
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
all: uint int
|
||||
all: uint int big parser
|
||||
|
||||
|
||||
uint: uint.o
|
||||
@@ -17,9 +17,17 @@ uint: uint.o
|
||||
int: int.o
|
||||
$(CC) -o int $(CFLAGS) int.o
|
||||
|
||||
big: big.o
|
||||
$(CC) -o big $(CFLAGS) big.o
|
||||
|
||||
parser: parser.o
|
||||
$(CC) -o parser $(CFLAGS) parser.o
|
||||
|
||||
|
||||
uint.o: uint.cpp
|
||||
int.o: int.cpp
|
||||
big.o: big.cpp
|
||||
parser.o: parser.cpp
|
||||
|
||||
|
||||
clean:
|
||||
@@ -27,4 +35,7 @@ clean:
|
||||
rm -f *.s
|
||||
rm -f uint
|
||||
rm -f int
|
||||
rm -f big
|
||||
rm -f parser
|
||||
# on MS Windows can automatically be added suffixes .exe to the names of output programs
|
||||
rm -f *.exe
|
||||
|
97
samples/big.cpp
Normal file
97
samples/big.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
// for convenience we're defining MyBig type
|
||||
// this type has 2 words for its mantissa and 1 word for its exponent
|
||||
// (on a 32bit platform one word means a word of 32 bits,
|
||||
// and on a 64bit platform one word means a word of 64 bits)
|
||||
typedef ttmath::Big<1,2> MyBig;
|
||||
|
||||
|
||||
void SimpleCalculating(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
std::cout << "Simple calculating" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
std::cout << "a + b = " << a+b << std::endl;
|
||||
std::cout << "a - b = " << a-b << std::endl;
|
||||
std::cout << "a * b = " << a*b << std::endl;
|
||||
std::cout << "a / b = " << a/b << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CalculatingWithCarry(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
MyBig atemp;
|
||||
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a + b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
std::cout << "a * b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a * b = (carry: the result is too big) " << std::endl;
|
||||
// it have no sense to print 'atemp' (it's undefined)
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Div(b) )
|
||||
std::cout << "a / b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a / b = (carry or division by zero) " << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
MyBig a,b;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456.543456";
|
||||
b = "98767878.124322";
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMax();
|
||||
|
||||
// at the moment conversions from double (or float etc.) are not supported
|
||||
// you cannot do that: b = 456.32f
|
||||
b = "456.32";
|
||||
|
||||
// Look at the value 'a' and the product from a+b and a-b
|
||||
// Don't worry this is the nature of floating point numbers
|
||||
CalculatingWithCarry(a,b);
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456.543456
|
||||
b = 98767878.124322
|
||||
a + b = 98891334.667778
|
||||
a - b = -98644421.580866
|
||||
a * b = 12193540837712.2708
|
||||
a / b = 0.0012499665458095765
|
||||
Calculating with a carry
|
||||
a = 1.624801256070839555e+646457012
|
||||
b = 456.32
|
||||
a + b = 1.624801256070839555e+646457012
|
||||
a - b = 1.624801256070839555e+646457012
|
||||
a * b = (carry: the result is too big)
|
||||
a / b = 3.56066193914542329e+646457009
|
||||
*/
|
@@ -1,4 +1,4 @@
|
||||
#include <ttmath/ttmathint.h>
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ void CalculatingWithCarry(const ttmath::Int<2> & a, const ttmath::Int<2> & b)
|
||||
{
|
||||
ttmath::Int<2> atemp;
|
||||
|
||||
std::cout << "Calculating with carry" << std::endl;
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
@@ -26,13 +26,13 @@ ttmath::Int<2> atemp;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a + b = (carry: the result is too big) " << atemp << std::endl;
|
||||
std::cout << "a + b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry: 'a' was smaller than 'b') " << atemp << std::endl;
|
||||
std::cout << "a - b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
@@ -52,17 +52,19 @@ ttmath::Int<2> atemp;
|
||||
int main()
|
||||
{
|
||||
// on 32bit platforms: 'a' and 'b' have 2-words (two 32bit words)
|
||||
// in other words a,b are from <-2^63, 2^63 - 1>
|
||||
// it means a,b are from <-2^63, 2^63 - 1>
|
||||
ttmath::Int<2> a,b;
|
||||
|
||||
// conversion from int
|
||||
a = 123456;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456";
|
||||
b = "98767878";
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMaxValue();
|
||||
a.SetMax();
|
||||
|
||||
// conversion from 'int'
|
||||
b = 10;
|
||||
@@ -71,7 +73,7 @@ ttmath::Int<2> a,b;
|
||||
}
|
||||
|
||||
/*
|
||||
the result:
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456
|
||||
@@ -80,11 +82,11 @@ a + b = 98891334
|
||||
a - b = -98644422
|
||||
a * b = 12193487146368
|
||||
a / b = 0
|
||||
Calculating with carry
|
||||
Calculating with a carry
|
||||
a = 9223372036854775807
|
||||
b = 10
|
||||
a + b = (carry: the result is too big) -9223372036854775799
|
||||
a + b = (carry) -9223372036854775799
|
||||
a - b = 9223372036854775797
|
||||
a * b = (carry: the result is too big)
|
||||
a * b = (carry) the result is too big)
|
||||
a / b = 922337203685477580
|
||||
*/
|
||||
|
34
samples/parser.cpp
Normal file
34
samples/parser.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// for convenience we're defining MyBig type
|
||||
// this type has 2 words for its mantissa and 1 word for its exponent
|
||||
// (on a 32bit platform one word means a word of 32 bits,
|
||||
// and on a 64bit platform one word means a word of 64 bits)
|
||||
typedef ttmath::Big<1,2> MyBig;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
ttmath::Parser<MyBig> parser;
|
||||
|
||||
// the sine function takes its parameter as being in radians,
|
||||
// the product from the arcus tangent will be in radians as well
|
||||
const char equation[] = " (34 + 24) * 123 - 34.32 ^ 6 * sin(2.56) - atan(10)";
|
||||
|
||||
ttmath::ErrorCode err = parser.Parse(equation);
|
||||
|
||||
if( err == ttmath::err_ok )
|
||||
std::cout << parser.stack[0].value << std::endl;
|
||||
else
|
||||
std::cout << "Error: "
|
||||
<< static_cast<int>(err)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
|
||||
-897705014.52573107
|
||||
*/
|
@@ -1,4 +1,4 @@
|
||||
#include <ttmath/ttmathuint.h>
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ void CalculatingWithCarry(const ttmath::UInt<2> & a, const ttmath::UInt<2> & b)
|
||||
{
|
||||
ttmath::UInt<2> atemp;
|
||||
|
||||
std::cout << "Calculating with carry" << std::endl;
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
@@ -53,17 +53,19 @@ ttmath::UInt<2> atemp;
|
||||
int main()
|
||||
{
|
||||
// on 32bit platforms: 'a' and 'b' have 2-words (two 32bit words)
|
||||
// in other words a,b are from <0, 2^64 - 1>
|
||||
// it means a,b are from <0, 2^64 - 1>
|
||||
ttmath::UInt<2> a,b;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456";
|
||||
b = "9876";
|
||||
|
||||
// conversion from int
|
||||
b = 9876;
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMaxValue();
|
||||
a.SetMax();
|
||||
|
||||
// conversion from 'int'
|
||||
b = 5;
|
||||
@@ -72,7 +74,7 @@ ttmath::UInt<2> a,b;
|
||||
}
|
||||
|
||||
/*
|
||||
the result:
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456
|
||||
@@ -81,7 +83,7 @@ a + b = 133332
|
||||
a - b = 113580
|
||||
a * b = 1219251456
|
||||
a / b = 12
|
||||
Calculating with carry
|
||||
Calculating with a carry
|
||||
a = 18446744073709551615
|
||||
b = 5
|
||||
a + b = (carry: the result is too big) 4
|
||||
|
Reference in New Issue
Block a user