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

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    8

    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
    You can download the installation script in the Worklog.

    Sorry for bad english!

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

    Thanks in advance,
    etlam

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    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.
    Last edited by Cactus_Hugger; 06-09-2007 at 12:48 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    8
    First, Thanks for your answer.
    I'll try to answer every point.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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.
    Quote Originally Posted by Cactus_Hugger View Post
    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?)
    Use rol instead.
    Quote Originally Posted by Cactus_Hugger View Post
    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?
    Quote Originally Posted by Cactus_Hugger View Post
    Otherwise, so far it is getting the correct answers. Well done.
    Thanks!

    etlam

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    8
    Yes, O.K.,
    I'll do this!

    etlam

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    8

    RoL Version 1.5.0

    Now Version 1.5.0 of RoL was realeased, coming with a lot of new features!
    Look here for the Anouncement and download o the installations script!
    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.

    Thanks in advance,
    etlam

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by etlam View Post
    -Can compute with numbers up to 2 147 483 647 digits.
    Then it's not really "without limits," is it?

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    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. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Jun 2007
    Posts
    8
    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. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    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()
    Last edited by Neo1; 02-04-2008 at 03:35 PM.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

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

    Quote Originally Posted by Neo1 View Post
    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)...

    Quote Originally Posted by Neo1 View Post
    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.

    Quote Originally Posted by Neo1 View Post
    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

    Thanks for your help,
    etlam

  14. #14
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    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...
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  15. #15
    Registered User
    Join Date
    Jun 2007
    Posts
    8
    Thank you!
    For the next version these names will be in english.

    etlam

Popular pages Recent additions subscribe to a feed