Download MetaTrader 5

working with 106 decimals

To add comments, please log in or register
abcmql4
11
abcmql4  
Hi all, I need your help with the following

First of all, I want to know if the calculations made in the language can be so accurate that results get to work with all these decimals.

Now I explain what I try.
I need to make a division for a number containing many decimals, 106 to be exact. the result should contain the same or more number of decimal places on most occasions. and I need that result in a "string"

I tried everything to see or take that value with all these decimals, but will not let me do it,

the situation is that after 15 decimal, round me, and I need not rounded, NO,

example, in case of the result is as follows:

I take a number in sequence to see how it behaves and how it is in the "string." 

double   ExtraLarge = 1.23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678;
string           SE = StringFormat("result  = %.100f ",ExtraLarge);

Print(SE);
//(PRINT) result = 1.2345678901234566904321354741114191710948944091796875000000000000000000000000000000000000000000000000 
//                                  >Here loses sequence, xxROUNDXX 


but the result is rounded, the sequence is also lost in the 14 decimal, and comes another set of numbers instead of sequences .....  678901234 .....which is expected or needed

How can I do, how I can take a "double" as well, a "string" will be of tremendous help ......

thank you very much 

peter.MT4Web
157
peter.MT4Web  

You can't do it with numbers the language and your hardware offers.

Search the net for a library calculating with strings or with special algorithms calcuating with chunks of the whole numbers.

abcmql4
11
abcmql4  
EDDIE, Thanks for your reply,
the idea of seeking libraries on the internet is the first thing that occurred to me, but I do not find the information I need.

I clarify that I do not need to process the information only from a "string", I need to process the "double" by multiplying and dividing it with another double, and in the end also, take that information and pass it to a "string"

The code example is clairvoyance that even in the simple task of putting the "double" in a "string" is not well done, do not even.

Thank you
peter.MT4Web
157
peter.MT4Web  

Again: You can't do it with numbers the language and your hardware offers.

Your numbers will never fit into a double. You have to use strings and call library functions for all your calculations.

Carl Schreiber
7239
Carl Schreiber  
Depending on what you want to do with this large number you might be able to factorise this number in smaller components like a*b*c*d*e = ExtraLarge;
GuBor
3
GuBor  

abcmql4:

Hi all, I need your help with the following

First of all, I want to know if the calculations made in the language can be so accurate that results get to work with all these decimals.

Now I explain what I try.
I need to make a division for a number containing many decimals, 106 to be exact. the result should contain the same or more number of decimal places on most occasions. and I need that result in a "string"

I tried everything to see or take that value with all these decimals, but will not let me do it,

the situation is that after 15 decimal, round me, and I need not rounded, NO,

example, in case of the result is as follows:

I take a number in sequence to see how it behaves and how it is in the "string." 


but the result is rounded, the sequence is also lost in the 14 decimal, and comes another set of numbers instead of sequences .....  678901234 .....which is expected or needed

How can I do, how I can take a "double" as well, a "string" will be of tremendous help ......

thank you very much 

What you need is an arbitrary precision library.

The question however is why you would need, or indeed would rely on arbitrary precision. You need a better understanding of number representation  before you throw an arbitrary precision library at a problem. Even in scientific computing, it is hardly ever needed! Models and algorithms for their numerical evaluation have errors that almost always exceed the cut-off and rounding error associated with double-precision number representation and operations.

Because external double-precision representations (64 bit=8 byte IEEE-754 format) of machine doubles (120 bit extended precision to allow all machine operations to be exact within the external 64 bit representation) have a 54 bit mantissa, machine epsilon (meps) is about 2e-16 ((1.+meps) - 1. >). That number 1.2345678901....(up to 106 digits) you gave might not even be exactly representable in an arbitrary precision library, unless it uses a rational number-based representation. Irrational numbers are not representable with a finite number of bits, even with an arbitrary precision library (you'll run out of memory eventually).

Also, and that is even worse: arbitrary precision number arithmetics is relatively and arbitrarily slow, in a large part exactly because it is not hardware-supported. You don't want arbitrary precision operations in the inner loops of your trading algorithms. And if it's for preliminary statistical analysis and backtesting/optimisation, modeling error and numerical error will most definitely trump the precision (15 to 16 significant figures) provided by doubles, unless you have a perfect theory of financial markets _and_ perfect numerical algorithms to solve/evaluate the theory's equations.

So, with all due respect, but I think your requirement for arbitrary precision is misguided...unless you use MQL4/5 for something else, of course :-)
To add comments, please log in or register