### Author Topic: Questions on Ceil and Floor  (Read 6139 times)

#### Endy

• Bot Overlord
• Posts: 852
##### Questions on Ceil and Floor
« on: March 07, 2005, 05:01:29 PM »
Thought of this code while converting Din, but can't seem to make it work correctly. :unsure:

A B sub sgn 0 floor  = 1 if A>B

A B sub sgn 0 ceil -1 mult = 1 if A<B

May be the dna itself, I've tried to check it but the sheer size of it is overwhelming right now. I suspect the ceil and floor commands are responsible. Possibly the new free store ability is causing some stack effects, and messing up the genes as a result but I would think Nums would have the values still be cleared from the stack.

Any help would be great,

Endy B)

#### Numsgil

• Bot God
• Posts: 7725
##### Questions on Ceil and Floor
« Reply #1 on: March 07, 2005, 05:15:40 PM »
How exactly is it not working?

Note that A B sub sgn will return 1 if A = B since 0 sgn = 1

The free store still takes two values from the stack.

#### Endy

• Bot Overlord
• Posts: 852
##### Questions on Ceil and Floor
« Reply #2 on: March 07, 2005, 10:31:06 PM »
Oops. :rolleyes:

Didn't realize that about sgn, I assumed that it would yield a zero since 0 is neutral. Darn DB math for not reflecting real math. :lol:

Endy B)

#### Numsgil

• Bot God
• Posts: 7725
##### Questions on Ceil and Floor
« Reply #3 on: March 08, 2005, 12:21:32 AM »
I can change it no prob.  That's just how the VB sgn function works.

#### Endy

• Bot Overlord
• Posts: 852
##### Questions on Ceil and Floor
« Reply #4 on: March 08, 2005, 09:24:27 PM »
I think it would be better if it was changed. I mainly use it for comparision between the two numbers, for stuff like greaterthan/lessthan and =/!=. With DB's 0/0 = 0 it is easier than normal to use the resulting zeros.

Endy B)

#### SyndLig

• Bot Neophyte
• Posts: 36
##### Questions on Ceil and Floor
« Reply #5 on: March 09, 2005, 11:19:26 AM »
So wait, in DB currently, 0 / 0 = 1 ?

#### PurpleYouko

• Bot God
• Posts: 2556
##### Questions on Ceil and Floor
« Reply #6 on: March 09, 2005, 11:25:54 AM »
No Actually in DB 0/0 = "Division by zero error"

It is just that 0 is considered a positive number in Visual Basic.

SGN is Boolean. It can only have two states.

:D  PY  :D
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

PY

#### Botsareus

• Society makes it all backwards - there is a good reason for that
• Bot God
• Posts: 4483
##### Questions on Ceil and Floor
« Reply #7 on: March 09, 2005, 02:22:58 PM »
(hint) Make it exactly like in vb:

+n -----> +1
0   -----> 0
-n ------> -1

#### shvarz

• Bot God
• Posts: 1341
##### Questions on Ceil and Floor
« Reply #8 on: March 09, 2005, 03:40:29 PM »
So, a gene like

cond
start
0 0 div
end

would crash the program?  Or there are safeguards?
"Never underestimate the power of stupid things in big numbers" - Serious Sam

#### Numsgil

• Bot God
• Posts: 7725
##### Questions on Ceil and Floor
« Reply #9 on: March 09, 2005, 04:12:21 PM »
0 0 div is undefine behavior.  Currently DB returns 0 for this.

And the VB sgn function works like this:

0 and + sgn = 1
- sng = -1

proof?

here's the code:

Code: [Select]
`'This one could be very usefulPrivate Sub DNASgn(robotnumber As Integer) 'returns sign of number on stack    Dim a As Integer    a = readst(robotnumber)        writest robotnumber, Sgn(a)End Sub`

#### PurpleYouko

• Bot God
• Posts: 2556
##### Questions on Ceil and Floor
« Reply #10 on: March 09, 2005, 09:36:25 PM »
As I said, in Visual Basic, SGN returns a Boolean state result with two possible outcomes. +1 or -1.

It cannot return zero unless you write a whole bunch of code to take the input of zero as a special case..

And yes there are safeguards against dividing by zero in DarwinBots.

:D  PY  :D
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

PY

#### Botsareus

• Society makes it all backwards - there is a good reason for that
• Bot God
• Posts: 4483
##### Questions on Ceil and Floor
« Reply #11 on: March 10, 2005, 01:11:03 PM »
'Microsoft Visual Basic 6.0
'Form1, no tricks
MsgBox Sgn(700) 'My vb is messed up it returns 1
MsgBox Sgn(0) 'My vb is messed up it returns 0
MsgBox Sgn(-700) 'My vb is messed up it returns -1
End Sub
'Enterpise Edition
« Last Edit: March 10, 2005, 01:12:25 PM by Botsareus »

#### Botsareus

• Society makes it all backwards - there is a good reason for that
• Bot God
• Posts: 4483
##### Questions on Ceil and Floor
« Reply #12 on: March 10, 2005, 01:14:46 PM »
'This one could be very useful , once you figure out the rest of the code (hint)
Private Sub DNASgn(robotnumber As Integer) 'returns sign of number on stack
Dim a As Integer

writest robotnumber, Sgn(a)
End Sub

MsgBox DNASgn(4) 'Good Luck with that, I dont have enough code to make it work
End Sub
« Last Edit: March 10, 2005, 01:15:42 PM by Botsareus »

#### Botsareus

• Society makes it all backwards - there is a good reason for that
• Bot God
• Posts: 4483
##### Questions on Ceil and Floor
« Reply #13 on: March 11, 2005, 03:26:39 PM »
Endy, they are lieing about that "Sgn()" function , I have just porved it. :D , no really: how come no one replyed?