| View previous topic :: View next topic |
| Author |
Message |
dmonckton Contributor


Joined: 09 Aug 2002 Posts: 117 Location: Lewes, U.K.
|
Posted: Tue Jul 08, 2008 2:56 pm Post subject: Negative number? |
|
|
Hi
Is this function the best way (resource efficient) to test for a negative number?
| Code: | :negative
if @greater(%1,0)
exit
elsif @zero(%1)
exit
else
exit 1
end
exit
|
Thanks
David... |
|
| Back to top |
|
 |
attreus Valued Newbie

Joined: 30 Jul 2002 Posts: 46 Location: Berlin/Germany
|
Posted: Tue Jul 08, 2008 4:14 pm Post subject: |
|
|
how about with this:
| Code: |
:negative
if @numeric(@substr(%1,1))
exit
else
exit 1
end
or better
:negative
if @less(%1,0)
exit 1
else
exit
end
|
edit:
here is one for the lazy
| Code: |
:negative
exit @less(%1,0)
|
another way would be
| Code: |
while @less(0,%1)
... do useful things such as
wait
wend
|
Last edited by attreus on Wed Jul 09, 2008 2:05 am; edited 1 time in total |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Tue Jul 08, 2008 5:50 pm Post subject: |
|
|
IMHO you should do the following...
| Code: |
:negative
%R =
%A = @pos(-,%1)
if @Greater(%A,0)
%R = 1
End
Exit %R
|
Thanks,
Dragonsphere _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Tue Jul 08, 2008 5:53 pm Post subject: |
|
|
IMHO I don't think it a good idea to break out of a IF with the Exit command.
Thanks,
Dragonsphere |
|
| Back to top |
|
 |
uvedese Contributor


Joined: 21 Jan 2006 Posts: 169 Location: Spain
|
Posted: Tue Jul 08, 2008 8:29 pm Post subject: |
|
|
What about this?
| Code: | :Negative
if @equal(@substr(%1,1),"-")
exit 1
else
exit
end |
_____________________
uVeDeSe
http://www.uvedese.es
______________________ |
|
| Back to top |
|
 |
dmonckton Contributor


Joined: 09 Aug 2002 Posts: 117 Location: Lewes, U.K.
|
Posted: Tue Jul 22, 2008 11:34 am Post subject: |
|
|
Thanks for all the ideas. I assume @less() is a VDS6 function? I have not moved on to VDS6 yet and not to sure I will!
Thanks again
David.M |
|
| Back to top |
|
 |
|