Code center > Suggestions

Make position a Single, not a Long

(1/4) > >>

Sprotiel:
I don't see any reason why robots' coordinates should be integers. In the current code, there's a lot of back and forth conversions between Longs and Singles. Eliminating those should reduce the probability of errors.

PurpleYouko:
Yes a very good point but you are heading in the wrong direction.

What we need to do is make everything long.

Why?

Because almost every crash in DB is due to some variable or other getting too big for a single or integer to cope with.

Robot position is a perfect case of this. At the moment the robot's readback in the memory array is a single length integer which means it has a maximum value of 32000 or so.
You will quickly notice when you run larger sims that this doesn't even begin to cut is as far as reading back realistic values. The largest present size has a Y coordinate maximum of 72000 and the X is even bigger. It used to crash immediately when we went above size 4 until Num "fixed" it by making it impossible for Xpos and Ypos to be greater than 32000.
This fixed the crash issue but it make the robot's coordinate system completely useless above size 4. The only real fix is going to be to port all variables (including memory positions) into longs. In modern windows applications this could even make the program run faster since windows is a 32 bit environment these days.

Sprotiel:
What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38?? :blink:

Concerning the crashes, I suspect what happened was the following: you tried to fit x^2 into a Long with x>32768 by writing

--- Code: ---Dim d As Long
d=Sqr(x^2+y^2)
--- End code ---

Concerning the robots, I don't see why their CPU needs to work with anything larger than an integer.

One more thing: I don't see the connection between the robots' memory and their position. They don't know their (x,y) coordinates nor should they.

Carlo:

--- Quote ---What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38?? :blink:
--- End quote ---

 :lol:

But don't you think that singles (that means single precision floating point) could slow down calculations? Maybe I'm wrong... I have simply no idea of the power of actual computers.


--- Quote ---One more thing: I don't see the connection between the robots' memory and their position. They don't know their (x,y) coordinates nor should they
--- End quote ---

I think they know them - PY or Numsgil added this feature. Initially I thought it was very stupid: everything was designed to give organisms only relative views on the environment. Well, I'm a bit less fundamentalist about that now. Most animals are able to orientate in the environment, and this is an important feature. Obviously, they do not have a GPS in their head, but, to some extent, it is like they do. But developing such a feature is probably impossible in the DarwinBots universe, not only because organisms are very simple, but also because of the nature of the DarwinBots environment, so poor of landmarks and allowing so limited senses.
So, maybe, it is not so bad that robots know their approximate position.

PurpleYouko:

--- Quote ---What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38??  

Concerning the crashes, I suspect what happened was the following: you tried to fit x^2 into a Long with x>32768 by writing
--- End quote ---

I don't know where you got that idea from.
In VB, the largest number that can be held in a single precision floating point variable or an integer is 32767. If you so much as add 1 to it then the program will return an overflow error and crash.

Just try running the following code in VB to see my point.
make a new form and place a command button on it. In the code for the button enter the following code

--- Code: ---Private Sub Command1_Click()
Dim count As Integer
While count < 40000
  Print count
  count = count + 1
Wend
End Sub
--- End code ---
Run the program press the button and wait for the error message.
Debug the program and hold the cursor over the variable "count"
The value displayed will be 32767. No more and no less.
This is the largest number that either a single or an integer will hold.

Navigation

[0] Message Index

[#] Next page

Go to full version