# Thread: Compute without Limit - support for fractions and 2G Digits!

1. ## Compute without Limit - support for fractions and 2G Digits!

I made a *.so Libary for Linux.
(This libary is called rol or Rechnen ohne Limit. Translated to english this would mean Compute without Limit.)
With this Libary, you can compute with numbers that can have up to 2 147 483 647 Digits!
These numbers can also have +/- (be positive/negative - how do you say this in english?).
Of course it supports numbers with a '.' in it (eg: 3.14).
It also supports fraction like one third. they are written like this: 1|3 .
Features:
-Can compute with numbers up to 2 147 483 647 digits.
-Can do*,/,+,-
-Can do <,>,==
-Supports .
-You can tell the Division how precise it should be.
-You can use it as .so libary
-You can migrate older Projects from normal to with Rechnen ohne Limit (-->english: Compute without Limit)
-It supports +/- (positive/negative)
-Fractions!

Look here for the anouncement of Version 1.4 : http://forum.etlamsoft.de/viewtopic.php?f=31&t=26

I would be glad if you could look at it and tell me what I could make better.

etlam

2. Couple of remarks. First, the header file cannot be included without first doing:
Code:
```#include <string>
using namespace std;```
Your header file should #include <string> itself. However, it should not do a using namespace std; - use std::string.

Your program, while it seems to work with "rols"/numbers (haven't tested this well yet), seems to break std::string. Consider this example:
Code:
```#include <string>
#include <iostream>

using namespace std;

#include "rol.h"

int main()
{
rol r;
std::string s1, s2;

r = "123";
s1 = "abc";
s2 = "def";
s1 = s1 + s2;
r = r + s2;

std::cout << s1 << std::endl;
std::cout << r << std::endl;

return 0;
}```
Which gives:
Code:
```+0
+123```
When the first line ought to read "abcdef". If you really want to use std::string to hold your numerical data, derive a class from it, name it rol, and get rid of the typedef.

You library appears to write temporary files. (And not clean them up?) Doesn't seem friendly to me, and a library such as rol really shouldn't need file I/O, should it?

Divison by zero locks up in what appears to be an infinite loop.
One of my nitpicks towards libraries of this nature: a*b may be faster than b*a, depending on how I ordered the operands. (In my test, 40 bytes of "123412341..." times "2000" took 1.353s or 0.335s. If it's faster to have one operand on one side, have the function do a length test, and swap operands if needed.

Speed: Finding 100! (factorial) is taking some time...

Finally, aside from your function names being in German(?):
Code:
`extern void multiplikation(string,string,string);`
I'm going to assume this does multiplication. If so, how does it return an answer? There is no return value, no pointers, no references. (And three arguments?)
My preference is to leave argument names in the header files. This clarifies at a glace what the argument to the functions are.

Otherwise, so far it is getting the correct answers. Well done.

I'll try to answer every point.
Originally Posted by Cactus_Hugger
Couple of remarks. First, the header file cannot be included without first doing:
Code:
```#include <string>
using namespace std;```
Your header file should #include <string> itself. However, it should not do a using namespace std; - use std::string.
Yes, I did forget to do that.
Will be fixed for next version.
Originally Posted by Cactus_Hugger
Your program, while it seems to work with "rols"/numbers (haven't tested this well yet), seems to break std::string. Consider this example:
[example]
Which gives:
Code:
```+0
+123```
When the first line ought to read "abcdef". If you really want to use std::string to hold your numerical data, derive a class from it, name it rol, and get rid of the typedef.
Huh? Strange. I'll have a look at this.
But you shouldn't add strings and rols.
Originally Posted by Cactus_Hugger
You library appears to write temporary files. (And not clean them up?) Doesn't seem friendly to me, and a library such as rol really shouldn't need file I/O, should it?
Yes, these files are there, because first I used functions like
division(string a, string b, string c);
Where these function took the two numbers stored in a and b (those strings are file names) and wrote the result in a file named c.
But eg. division uses temporary files from the addition, so I can't delete them there.
Those function are still used inside rol addition.
For next version, I'll try to delete those files, or store them in a extra folder.
Originally Posted by Cactus_Hugger
Divison by zero locks up in what appears to be an infinite loop.
Mhh...
I will test at the beginning if its divisded by zero, but what should then the result be?
I have to think about that.
Originally Posted by Cactus_Hugger
One of my nitpicks towards libraries of this nature: a*b may be faster than b*a, depending on how I ordered the operands. (In my test, 40 bytes of "123412341..." times "2000" took 1.353s or 0.335s. If it's faster to have one operand on one side, have the function do a length test, and swap operands if needed.
I havent understanded that good.
Do you mean a big number * a small number is faster?
Or a small number * a big number is faster?
I'll have a look at this.
But maybe, instead of doing the test, I could look at why this happens, and make it equal-fast.
I think this happens because of something in the main loop, and a few times the main loop by a lot times the small loop is faster than a lot times the main loop by a few times the small loop.
Originally Posted by Cactus_Hugger
Speed: Finding 100! (factorial) is taking some time...
Yes, for next Version I'll make support for root and power and the things you wrote here.
And than, for the Version after that I'll look at the speed.
Originally Posted by Cactus_Hugger
Finally, aside from your function names being in German(?):
Code:
`extern void multiplikation(string,string,string);`
I'm going to assume this does multiplication. If so, how does it return an answer? There is no return value, no pointers, no references. (And three arguments?)
These functions are old!
Look to the up (How do you say that in english?)
Originally Posted by Cactus_Hugger
My preference is to leave argument names in the header files. This clarifies at a glace what the argument to the functions are.
I havent understanded this.
Could you please repeat this in easier english?
Originally Posted by Cactus_Hugger
Otherwise, so far it is getting the correct answers. Well done.
Thanks!

etlam

4. My preference is to leave argument names in the header files. This clarifies at a glace what the argument to the functions are.
I havent understanded this.
Could you please repeat this in easier english?
Leaving argument names in makes function prototypes easier to read. Which makes more sense? This?
Code:
`string fullname(string, string);`
Or this?
Code:
`string fullname(string firstname, string lastname);`
Hint: the second one.

5. Yes, O.K.,
I'll do this!

etlam

6. ## RoL Version 1.5.0

Now Version 1.5.0 of RoL was realeased, coming with a lot of new features!
See here for the worklog
This is a tutorial explaining how to use RoL.

Whats new in this Version:

- I overloaded +,-,*,/,!,==,>,< for the class rol.
- rol can be used nearly as easy as for example int.
- Much faster now
- No use of temporany files anymore
- new mathematical functions: to the power,root, exp, ln, abs , min, max
- trigonometric Functions: sinx, sina, cosx,cosa,tanx,tana,cotx,secx,cscx, sinh, cosh, tanh, coth, sech, csch (sinx means as radient and sina means as °)

If you find bugs or want to ask something you can also write it to the forum related to Rol.
I would be glad if you could look at it and tell me what I could make better.

etlam

7. Originally Posted by etlam
-Can compute with numbers up to 2 147 483 647 digits.
Then it's not really "without limits," is it?

8. @brewbuck: Not really - but I think 2G digits has a touch of unlimited.
The biggest known prime number has a bit under 10M digits, and they needed more than a month to compute it.
And its not very likely that someone would need more than 2G digits...

etlam

9. Have you considered extending that to a 64-bit size for 64-bit architecture machines - it should add very little extra execution time, and whilst the number of digits is sufficient for large integer calculations, should you wish to calculate something like pi to many digits precision, you may find that 2G digits isn't quite sufficient.

--
Mats

10. Yes, with that you dont need more than 2G I meant the normal things, but Pi is one thing where this isnt enough.
I already thought about this for 64 Bit machines, but the problem is that I dont have a 64 Bit machine, where I could test this.
I could also use multidimensional arrays, but this would slow down everything, and I thought that it wouldnt be worth if for the part of the users, which dont need more than 2G its lets say 20% more time.

etlam

11. The other problem with 32-bit machines is of course that you are limited to about 3GB of user-space memory, so even if you have huge amount of memory, if you have many parts in the calculation, you won't even get close to 2G digits in a number when you are limited by the size of the user-space memory. Again, 64-bit machines should solve that.

A 64-bit processor + motherboard + memory shouldn't set you back very much - about 300 euros should get you a decent system with a reasonable amount of memory - you do want something with more than 4GB if you REALLY want to show that it can do more than 2G digits tho', so you may need to get into either more expensive motherboard and/or memory sticks for that - but for the initial implementation you don't need anythign more than a simple Athlon64 or late-ish Intel Pentium 4/Core 2 processor.

--
Mats

12. This is what i reckon would be the best translation, my german is limited though, so there might be room for improvement...

Code:
`nachkommastellenkuerzen(rol x,3);`
Basically what this does is to remove digits after the comma (nach komma), in english this is called Rounding, so perhaps something like this:

Code:
```round()
roundoff()
loseprecision()```
On the forum you linked to, you wrote that:
rol hoch(rol a, rol b);
this does a^b
By a^b i presume you mean a to the power of b? And not a XOR b? If so then this function basically does the same as the pow() function in the math.h header(link), so i guess one of these names would suffice?

Code:
```pow()
exp()```
Perhaps it's best to avoid pow() since it's already in math.h, best not confuse everyone

rol wurzel(rol x, rol n);
this is the opposite of ^ (called radical?)
it does the nth radical(???) of x.
I'm not quite sure i understand this one. The inverse function of exp() is the natural logarithm, but you already have that function named as ln(), so what is this one then? Could it be Nth root?

Code:
```root()
nroot()```
abs(rol x);
This changes the +/- to +.
This is called the absolute value, so i don't think you really need to change this one Alternatively you could call it:

Code:
`absvalue()`
ln(rol x);
The naturally logarithm of x.
No need to change this either

If you have any other functions you need translated, or variables, just let me know, be happy to help...

Edit: Looks like i mixed up THE exponential function and exponentiation in general. With this in mind i don't think you should name your function exp(), but rather pow()

13. Thank you, that will relly helped me.
For the next Version I will name the functions in your translations.
Originally Posted by Neo1
Code:
```round()
roundoff()
loseprecision()```
I will use loseprecision here, because this is what the function was first for.
Originally Posted by Neo1
By a^b i presume you mean a to the power of b?
Yes, its the a to the power of b.

Originally Posted by Neo1
Perhaps it's best to avoid pow() since it's already in math.h, best not confuse everyone
I think I will use something like rpow (r for rol)...

Originally Posted by Neo1
I'm not quite sure i understand this one. The inverse function of exp() is the natural logarithm, but you already have that function named as ln(), so what is this one then? Could it be Nth root?
In RoL, exp means e to the power of something, and ln is the reverse one.
With wurzel I mean the nth root. I will call it root.

Originally Posted by Neo1
If you have any other functions you need translated, or variables, just let me know, be happy to help...
Maybe you could help translate the variables, which control the accuracy.
You find them here

etlam

14. long division_nachkommastellen;
The direct translation of this would be division_placesaftercomma, but perhaps you should go with division_digitsaftercomma or division_precision? Up to you

long ln_nachkommastellen_genauigkeit;
Same as above, genauigkeit translates to accuracy or precision. ln_digitsaftercomma_accuracy ? Perhaps you should change this one if you plan on translating it

long wurzelgenauigkeit;
Something along the lines of nroot_accuracy.

long wurzelgenauigkeitnks;
This one is abit strange as well. Maybe nroot_accuracy_dac? Where dac == nks...

long hochnks;
rolpow_dac

long expgenauigkeit;
long expnachkommastellen;
long singenauigkeit;
long sinnks = 10;
exp_accuracy
exp_dac
sin_accuracy
sin_dac

But those 4 are very confusing/interchangeable, i think you should comment your code very well if you chose those names...

15. Thank you!
For the next version these names will be in english.

etlam