Poll

Read post then answer

Modular math
4 (66.7%)
Simple Cap
0 (0%)
Wrap Around
0 (0%)
Keep stack as integers
2 (33.3%)

Total Members Voted: 6

Author Topic: Stack as longs  (Read 3104 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Stack as longs
« on: June 09, 2005, 11:22:37 AM »
In working on the DNA language, I realized that everything we'd want more space for (well, almsot everything) than an integer can provide are involved in more complex stack manipulations more than storing to memory.

For instance, say you want to find the magnitude of a vector defined as <200,200>.  The only way I really know to do it is take 200^2 + 200^2 and then square root it.

However, while 283 (the magnitdue) is less than 32000, the intermediate values you need to use to find 283 are much larger (80000 at one point).

So if we allow stack manipulations to use longs, this solves the problem.

Then, of course, we have to decide what to do when you try storing 86 million to .up.  There are some possibilites:

1.  Modular math.  32001 = 1.  This is similar to bit shifting.
2.  Simple cap.  32001 = 32000.
3.  Wrap around.  32001 = -32000

I'd favor modular math.

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Stack as longs
« Reply #1 on: June 09, 2005, 02:58:59 PM »
I disagree. First, I don't see the problem: bots have no need for computing the norm of (200;200). Second, you can divide both numbers by 10, square and add them and take the square root. OK, you'll get 280 but does it matter ?
Third, your "modular math" make no sense: you get 31000 + 2000 - 2000 = -1000. The modular stuff is actually what you call "wrap around".


Now what I'd like would be to have conventional signed 16 bit-integers in the stack, without artificial bounds or checks. It's a pity there's no simple way to tell VB that we want 32767 + 1 = -32768 instead of throwing an overflow error.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Stack as longs
« Reply #2 on: June 09, 2005, 03:44:01 PM »
No, modular math makes perfect sense.  What I called modular math was wrong.  So shoot me.  What I meant #1 to be was sort of like if you take an integer and only use the lowest 8 bits.

Modular math should go like:

31000 +2000 - 2000 = 31000.  31000 + 2000 = -31000.  -31000 - 2000 = 31000

The normal was just an example, but it has cropped up in the past.  There are ways to use vectors to steer the bots, but you always have the problem of finding the magnitude.  You have to do all that fancy divide by 100, multiply by 100 stuff.

For instance, when I first found DB I made a way to find the sine of a number.  But it's accuracy was limited because 32000 isn't very large.  I couldn't do the full unit circle, I had to stick with the first quadrant.

This would solve those kinds of problems hopefully.
« Last Edit: June 09, 2005, 03:46:30 PM by Numsgil »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Stack as longs
« Reply #3 on: June 09, 2005, 04:10:56 PM »
Only keep long calculations in there own functions, make sure all final results are with in integer range. This way we wont have to rewrite the whole thing, only add a few new functions.

But if you going the way of keeping basic prinsiples of math instead of new complex functions then we have no choise but to use stuff bigger then integer.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Stack as longs
« Reply #4 on: June 09, 2005, 04:14:35 PM »
Remember the array for the bots stays as integers, but the stack becomes bigger.  Trying to make memory into longs would give the bots way too many value possibilities and confuse the heck out of them.

We already have the problem of 2000 .up store.  We don't want to compound it.