wondering how to set how long parser.stack[0].value is in char
i'm trying to make a simple program that that finds pi to the nth degree, i thought about making a class
of my own with a bunch of operator over loaders and a function that returned a string to output but then chose
to look to see if something like this had already been done after trying about three different Bignum c++ libs
this was my favorite as it had a parser and was just easy to setup and run. i am how ever a bit in dismay as i
would like to set the length of the output string so i might ask the user to how many decimal places they would
like to find pi to and then store that in say an int called NODP and then run some function for or with somthing
like say my parser and call it like so
parser.SetStringLenght(NODP+2) //+2 acounts for 3 and . in pi
It is impossible to have such a method as parser.SetStringLenght(NODP+2) in ttmath library. How long the values can be is set at *compile* time. You have to know how big your values are and get appropriate container.
Consider this type:
typedef ttmath::Big<TTMATH_BITS(64), TTMATH_BITS(512)> Float;
Here we have 512 bits for the mantissa (both on 32 and 64 bit machines). The max integer value which can be
stored on 512 bits is:
2^512-1
and how many decimal digits it takes:
log( (2^512-1); 10)-1 = 153 (-1 for rounding)
You can check it in this sample program:
#include "ttmath/ttmath.h"
#include <iostream>
typedef ttmath::Big<TTMATH_BITS(64), TTMATH_BITS(512)> Float;
int main()
{
Float a;
a.SetMax();
std::cout << a << std::endl;
ttmath::Parser<Float> parser;
if( parser.Parse("10/3") == ttmath::err_ok )
std::cout << parser.stack[0].value << std::endl;
}
Above parser will produce values with about 153 decimal digits. There is no way to change it when the program is running. You can do it only at compile time.
thanks i didn't think about calculating how long the digits would be, but this dose not solve my problem
as i want to output during runtime.
why wont this work(i haven't tried it yet, i will though)
int main() {
int NODP;
cin>>NOPD;
int BitsNeeded = (something that uses NOPD to find number of bits needed);
typedef ttmath::Big<1,BitsNeeded> MyBig
ttmath::Parser<MyBig> parser;
ttmath::ErrorCode err = parser.Parse(
" 123 - 432 * (12 / 3) ^ 54.34 - 10 * pi");
std::cout << parser.stack[0].value << std::endl;
}
o and one more thing, i don't care about how big the ttmath container is, my original plan was to just give it a really big number like 1000 bits for the decimal place and then 1 bit for number, then i was hoping i could put it in another variable like std::string and just run a loop out putting string[i] as it went along and the loop ending when i==N'th digit