Files
ttmath/samples/parser.cpp
Tomasz Sowa a40e951923 fixed: Big::ToDouble(double &) set always +INF (infinity)
when the value was too large (even for negative values)
       (it should set -INF in such a case)
added: some missing methods for converting
       for UInt<>, Int<> and Big<> classes:
       uint ToUInt()
       sint ToInt()
       ToUInt(uint32_t &)
       ToInt(uint32_t &)
       ToInt(int32_t &)
       ToUInt(uint64_t &)
       ToInt(uint64_t &)
       ToInt(int64_t &)
       FromUInt(uint32_t &)
       FromInt(uint32_t &)
       FromInt(int32_t &)
       FromUInt(uint64_t &)
       FromInt(uint64_t &)
       FromInt(int64_t &)
       and appropriate constructors and operators
       *** version for 64 bit platforms are not tested yet ***
added: double Big::ToDouble() /there was only Big::ToDouble(double &) /
       uint Big::ToFloat(float &)
       float Big::ToFloat()



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@316 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-22 19:43:12 +00:00

40 lines
969 B
C++

#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.525731067
*/
/*
the result (on 64 bit platform):
-897705014.5257310676097719585259773124
*/