ID:138124
 
2 questions:

1. Is there any limit to the complexity of a mathematical equation in Byond? or a limit to the answer?
could it for example calculate numbers with thousends of zeros on the end? is there a limit to the size of the anser it can output?

2. if spawn(1) causes an event to happen after 1/10th of a second, how fast is it without the spawn proc?
what is the standard delay?
if for example i had:

mob/verb
Example()
usr << "This is an example"
usr << "example number 2"

and then i click the Example() verb, the two lines of text appear to be dsiplayed simulatneously. but im guessing there must be a standard delay that it can run at. if so waht is it?
On 3/16/01 5:20 am Mloren wrote:
2 questions:

1. Is there any limit to the complexity of a mathematical equation in Byond? or a limit to the answer?
could it for example calculate numbers with thousends of zeros on the end? is there a limit to the size of the anser it can output?

If you are planning to store your result as a single number, you are limited by the single-precision floating point (32-bit) currently used to represent numbers. The approximate range of values is (looking in my C manual):

min: 1.175494351 E – 38
max: 3.402823466 E + 38

not exact precision, but values have a pretty large span.

On the other hand, you can do arbitrarily sized computations by storing your (large) numbers in strings, parsing the strings, and breaking them up into smaller computations. Some numerical libraries have been written (in C++, Fortran, etc) to compute thousands of digits of PI in this way.

2. if spawn(1) causes an event to happen after 1/10th of a second, how fast is it without the spawn proc?

Without spawning, instructions occur as fast as possible (as determined by the cpu on the server). Since BYOND isn't really multithreaded, the spawned event may not occur exactly in the time specified-- the server must finish processing the current proc before it can get to the spawned events.
In response to Tom H.
ok...
is it easy to split the numbers up like you were saying? im not really sure i understand what you mean by splitting it up.

I want it to handle a number containing a million diggits =p
In response to Mloren
is it easy to split the numbers up like you were saying?

Nope. =)

im not really sure i understand what you mean by splitting it up.

Here's an example:

"18529203952587358"

Then say you want to add that to

"12065617603683764"

You would break away the first string's last digit, 8
and add it to the second string's last digit, 4
which would yield 12 ones (or 2 ones plus 1 ten). Then you would break up the first string's second-to-last digit, 5
and add it to the second string's second-to-last digit, 6
and add the tens digit of the first result, 1
which would yield 12 tens... and 2 ones plus 12 tens is 122.

So far, you have the last two digits of each string added together: i.e.

"...58" + "...64" = 122


You'd have to go through the process of adding every single digit together. It takes time and a lot of processor memory, more so with every increasing value. As far as the process is concerned, when you begin to get into numbers larger than 4 billion the process begins to degrade in speed and actually becomes less desireable.

I could write a library to do it for you, but I'd really rather not. =P

Though it's not capable in BYOND, in machine-language-generating code you can specify any arbitrary number of bytes to store a piece of information, theoretically giving you the ability to have an unlimited number. Unfortunately, they require quite a large amount of code, especially taking into consideration that you not only have to tell the compiler to reserve that amount of memory, but also HOW to reserve that amount of memory. Normal short and long variables (speaking from a C++ perspective) don't need that.


I want it to handle a number containing a million diggits =p

Um?! Actually, BYOND wouldn't be able to handle that; you're talking about one million bytes (i.e. 1 megabyte) of data to be processed in one go. Not very efficient. Other single-player games might be able to get away with it, but in an online multiplayer game... no way.

You might like to note that programs devoted to calculating pi actually require their own mainframe server to be capable of handling the amount of data that is processed.

Instead of dealing with large numbers, you should scale things up; i.e. instead of calculating the distance from Earth to Neptune in kilometres, do it in astronomical units.
In response to Mloren
On 3/18/01 8:24 pm Mloren wrote:
ok...
is it easy to split the numbers up like you were saying? im not really sure i understand what you mean by splitting it up.

It's not too bad. You can just use a list and have each member represent a power of ten. So your number would be:
list_entry[1] + 10*list_entry[2] + 100*list_entry[3] ...

We've been discussing having BYOND coding contests for a while now-- once this web site is all finalized we will get to staging a few things. I'm thinking that a "funky library" contest would be a lot of fun. A routine to do arithmetic with large numbers would be a neat project. I've done it in C using arrays, so it is definitely do-able in BYOND.

A million digits is a bit much, though! Do you have any idea how big that is? :)
In response to Tom H.

A million digits is a bit much, though! Do you have any idea how big that is? :)

yes :)
see its not for my game, i was just curious...
they say that the googleplex (a 1 with a million 0s) is the largest writern number (how someone managed to write that is byond me .... ;p)
but i thought i would try to make a program taht started at 1 and then at a very fast rate added 1 to it and outputed the number...
ie it would display:
1
2
3
4
5
etc
and i want it to exceed a googleplex :p
well never mind.... i was just curious