|
|||||||
This is a discussion on "longer numbers?" in the Top Mud Sites MUD Coding forum : Is there any possible way to make a number that is larger than 2,147,483,647 on an LP mud? Specifically: Im running a heavily modified LPMud 2.4.5 on Amylaar driver...... |
|
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our MUD community today! If you have any problems with the registration process or your account login, please contact us. If you are a registered member of the old TMS forums, please click here
|
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Is there any possible way to make a number that is larger than 2,147,483,647 on an LP mud?
Specifically: Im running a heavily modified LPMud 2.4.5 on Amylaar driver... |
|
|
|
|
|
#2 |
|
Member
Join Date: Apr 2002
Home MUD: DartMUD
Posts: 86
![]() |
Well, there's always the floating point type, float. I'm not exactly sure what the maximum value a float can have but it's somewhere between 1x10^300 and 1x10^400 (it's implimentation dependent.) Of course, this doesn't give you same granularity as integers, but it will hold larger numbers. Also, floating point operations are significantly more CPU intensive. Finally, the driver you are using has to have floating point support compiled in.
|
|
|
|
|
|
#3 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Yeah I have tried using float but it is still the same, just lets me use decimals =/
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Here are my testings...
> eval return "/sys/enziet.c"->conv( 2147483647 ); Got: "2,147,483,647" > eval return "/sys/enziet.c"->conv( 2147483648 ); Got: "-2,147,483,648" > eval return "/sys/enziet.c"->conv( 2147483649.9 ); Got: "2.,147,48e,+09" > eval return "/sys/enziet.c"->conv( 2147483649 ); Got: "-2,147,483,647" > eval return "/sys/enziet.c"->conv( 2147483648 ); Got: "-2,147,483,648" > eval return "/sys/enziet.c"->conv( 2147483647 ); Got: "2,147,483,647" > eval return "/sys/enziet.c"->conv( (long)2147483647 ); Error in compiling statement: "exec_foo() { return "/sys/enziet.c"->conv( (long)2147483647 ); } "*Error in loading object: 'players/enziet/EVAL'. > eval return "/sys/enziet.c"->conv( (float)2147483647 ); Got: "2.,147,48e,+09" |
|
|
|
|
|
#5 |
|
Member
Join Date: Apr 2002
Home MUD: DartMUD
Posts: 86
![]() |
Well, yes...that's to be expected. What precisely are you trying to use this for?
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Im tinkering around with making a MUD based on the Dragonball anime series... and well... the EXP is the 'powerlevel' and it seems squite easy, and needed, to get over 2bil... I just really dont want to end up using SMAUG or something, I'd much rather prefer LPC
|
|
|
|
|
|
#7 |
|
Member
|
For very large numbers you can 'roll your own system'.
Pseudocode; [code] internally have 2 (or more vars) int exp1 int exp2 int exp1_max = 100000; When adding; exp1+= add while (exp1 >= exp1_max) { exp2++ exp1 = exp1 - exp1_max } When displaying; "You have %d%05d exp.", exp2, exp1 [/quote] This will, by using two ints, allow for numbers approaching 214748364700000 (which is 214 trillion for you americans out there, and 214 billions to the rest of us. See this page for details.) As a side note - even though I see that following the theme of dragonball is a main focus - I think a design that needs numbers in that range is absurd. There is nothing preventing you from just doing this: [code] "You have %d000 exp.", exp [/quote] When dealing with numbers up to 2.1 billion, you don't really care about those small changes below 1k, do you ? This little change should give you enough for the first 2k billions. (2 trillions) and doesn't give you any extra trouble. In short - if you need such high numbers, your design is flawed. |
|
|
|
|
|
#8 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Actually, the only problem is displaying the numbers...
So I fixed it, and I can now display numbers far greater than I even know what to call them (200+ digits long). Thanks for your help! |
|
|
|
|
|
#9 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Hrmm, well... still cant ADD/subract more than 2,147,483,647.
-.- I was so close Any ideas on adding/subtracting more than that? Multiplying? Dividing? Here is the method I used to add/subtract: (With this I can this can hold/show numbers up to 999,999,999,999,999,999) [code] #define MAX 999999999; int number1; int number2; int actual_num; _add( int amount ) { actual_num += amount; number1+=amount; while( number1 < 0 ) { number2--; number1 = number1+(MAX+1); } while( number1 > MAX ) { number2++; number1 = number1-(MAX+1); } return 1; } [/quote] Multiplying works... not so good if the number is ever our famous limit.... [code] _mult( int by ) { int i, temp; temp = actual_num; for( i=0;i<(by-1);i++ ) { this_object()->_add( temp ); } return 1; } [/quote] I could post my code that actually shows numbers that large, but it's lengthy so unless you really want to see it, I'll leave that be for now. |
|
|
|
|
|
#10 |
|
Posts: n/a
|
I would have to agree, unless you are using down to the single digit then why not go with /10th or even /100th of what numbers you are trying to work with? I am unfamiliar with the Dragonball theme, so maybe it is needed.
Unless you find a trick to display the numbers, i'm not sure you will have much success. I don't currently know of any of the normal LPC servers that support big numbers. Currently though, it isn't much of a problem with Pike, as it can be compiled with bignum support. =) I'm sure my server written in Pike (GenLPC) could be modified to work with COMPAT mode mudlibs, but right now i'm attempting to get it to have a larger measure of compatibility with Native. Compat libs will require a load of simulated efuns to maintain compatibility, something I'm not keen to work on just yet. Though the point still remains, do you -really- need numbers that large? )Kaylus@Solice |
|
|
|
#11 |
|
Member
|
200+ digits ? Why would ANYONE need numbers of that size ?
(to give an idea about just how absurd this is, consider the number of atoms in the universe is estimated at 1e79 (See this site for details.) I remember back in high school we had a calculator program capable of 'unlimited length'* numbers. It could add, subtract and multiply, divide, calculate square root etc. . We used it to calculate pi to thousand decimals, to see if this high precision would allow for us to solve the circle/square problem (I don't remember the exact name, it's 15 years ago...) - of course the math program just showed us that no matter the accuracy, pi is still not expressable in decimal form. It also showed us that when you get past the first 10-12 digits, the rest is academic**. Welcor * limited by memory, which at the time was, I think, 64 or 128K. ** Academic = not worth it. |
|
|
|
|
|
#12 |
|
New Member
Join Date: Jun 2002
Posts: 10
![]() |
Well, obviously it seems that Ido need numbers that large, probably wont need any past 500 trillion for a very long time...
Im not concerned as to WHY I need them, just figuring out HOW to use them... Can I get more info on Pike? |
|
|
|
|
|
#13 |
|
Member
|
The large number calculator I mentioned in the earlier post, worked on strings (arrays of char), dynamically allocated to fit the size wanted - pseudo code:
[code] string _add(string num1, string num2) { int i, j, s = 0; string result, t1, t2; if (strlen(num1) < strlen(num2)) { t1 = num2; /* longest */ i = strlen(num2); t2 = num1; /* shortest */ j = strlen(num1); } else { t1 = num1; /* longest */ i = strlen(num1); t2 = num2; /* shortest */ j = strlen(num2); } for (;i >= 0 || s;i--, j--) { if (j>= 0) s = t1[j] + t2[i] + s; else if (i >= 0) s = t2[i] + s; result[i] = s % 10; s = s / 10; /*transfer extra */ } return result; } [/quote] This method (or something similar - the above is mailer code) can be used for all wanted calculations. To output this string afterwards, just print it with a %s conversion. Welcor |
|
|
|
|
|
#14 | |
|
Posts: n/a
|
Pike is one of the faster "scripting"/interpreted languages. It is the brainchild of Fredrik Hübinette, after playing around on some LP muds a long while ago he decided to write his own dialect based on it and wrote a server (LPC4), it was still under the LP license agreement which meant that anything written for the dialect couldn't be used commercially. In 1994 Fredrik Hübinette started writing µLPC which grew and evolved into Pike.
Pike is a standalone scripting language with many similarities to LPC, with alot of builtin modules and some other features. It was a marked change from LPC though in that it doesn't have a server with it, just an interpreter. I had to write the server myself in Pike, which ended up working just as well. I learned alot about Pike that way. It has all the data types: int, string, float, function, mapping, multiset, array, programming, object (Pike Datatypes and all of the operators, as well as some neat ways to use them Pike Operators, operator overloading.. blah =) I gave the links. Now to the point you like, the language can be compiled with bignum support to allow integers of arbitrary size. Exactly how big - I have not tested. Take this information from the unofficial FAQ Quote:
Pike is more popular in europe, and hasn't taken hold in the U.S. like Python has. A few big projects, that I know of, have been made with Pike, most notably the Roxen Webserver. Pike Document Page Unofficial Pike Faq* If you are interested after taking a look at Pike, then just send me a message to kaylus@[REMOVE]solice.org and i'll be glad to talk with you about getting an alpha copy of my GenLPC and a small testlib, as well as whatever help you need =) * Has a nice pro's and con's a few pages in. |
|
|
|
|
#15 |
|
New Member
Join Date: Jul 2002
Location: Canada
Posts: 17
![]() |
I don't know what you're coding in, but my C compiler under linux supports
the 64 bit long long declaration: long long i = 0; I'm not sure what the endpoints are for 64 bits, but their probably more than what you expect to need for a long time (way past trillions). |
|
|
|
![]() |
| Thread Tools | |
longer numbers? - Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Threshold is no longer pay-to-play. | Threshold | MUD Announcements | 5 | 10-03-2007 09:07 AM |
| No Longer Moderator | Ntanel | MUD Announcements | 0 | 11-06-2005 11:17 PM |
| No longer offering free avatar on Ancient Chaos | Greetmir | Advertising for Players | 0 | 06-04-2005 03:15 AM |
| hex numbers | Emit | MUD Coding | 2 | 10-01-2002 12:05 PM |
|
|