Page 1 of 1 1
Topic Options
#133704 - 2005-02-12 10:24 PM Integers vs. Long Integers
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I hate asking stupid questions, but for the life of me I cannot find an explaination that is in terms I can make any since of. What is the difference between Integers and Long Integers. I've googled and found the 64bit/32bit explainations... sorry, that doesn't help. I thought an integer was a whole number, but obviously there is something more to it than that. I wrote a little test script just to see what would happen:

Code:
 
break on

for $i=1 to 20
? "" + $i + ":" + vartype($i)
sleep 1
next



In this example, every number is a vartype of 3 (Long Integer). So my second question is, where in kixtart would you find a Integer (not Long Integer)?

Top
#133705 - 2005-02-12 11:03 PM Re: Integers vs. Long Integers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, heres my take:

An integer is a signed numeric value. A long integer is a four-byte signed numeric value. A short or word is a 2 byte signed numeric value. A byte integer is a 1 byte signed numeric value.

Bottom line (imho) is there the same, one has a specified length (long) and one is unspecifed - so the length may depend.

Top
#133706 - 2005-02-12 11:23 PM Re: Integers vs. Long Integers
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Let me rephrase my second question.

When in kixtart would you ever see a value that was a vartype=2?

Top
#133707 - 2005-02-12 11:42 PM Re: Integers vs. Long Integers
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I guess it would be appropriate to refer to the KiXtart Manual:
Quote:


Variable types
In KiXtart, variables are always of one fundamental data type: Variant. The current implementation of KiXtart uses three types of variants: long integers, doubles (8-byte floating point numbers) and strings. A variant of type string can contain up to 32,000 characters. Integer variables can contain any value between -2,147,483,648 and 2,147,483,647. The type of a variable is automatically changed to the result of the expression that is assigned to it. This means that if you assign a string to a variable containing an integer, the type of the variable is changed to a string.





I don't think you'd see an Integer, the number might just be available due to the API Ruud is using to get the variable type.
_________________________
There are two types of vessels, submarines and targets.

Top
#133708 - 2005-02-12 11:45 PM Re: Integers vs. Long Integers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I am wondering if perhaps COM may in some case return an integer that is not a long.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133709 - 2005-02-13 12:06 AM Re: Integers vs. Long Integers
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The the question remains whether Kixtart will automatically convert to a Long Integer.
_________________________
There are two types of vessels, submarines and targets.

Top
#133710 - 2005-02-13 12:32 AM Re: Integers vs. Long Integers
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Quote:


KiXtart uses three types of variants: long integers, doubles (8-byte floating point numbers) and strings





Thanks Jens... that looks like that answers the question right there. Since I rarely write any code other than kixtart, I guess I don't have to worry about the other types of integers.

Top
#133711 - 2005-02-13 12:41 AM Re: Integers vs. Long Integers
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
It is questions like this that seem to hold us dedicated KiXtart user's attention. Shawn where is your conversation with Ruud? Topics like this would be great conversation.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#133712 - 2005-02-13 02:00 AM Re: Integers vs. Long Integers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
If the COM object returns a two-byte integer to Kix, than Kixtart uses it ... if the COM object returns a 1 byte integer, than Kixtart uses that - I just tested this myself by doing a VarTypeName on some integers from COM object ...

E:\docs>kix32 t

vartypename = Integer

vartypename = Byte

But heres the thing - nobody uses these 2 and 1 byte integers, most COM objects just return four-byte integers (aka) longs. The term "integer" by itself, i think (historically) refers to the two byte flavor, which I think no one uses.

-Shawn

Top
#133713 - 2005-02-13 02:24 AM Re: Integers vs. Long Integers
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
More info on integers is in the WikiPedia at http://en.wikipedia.org/wiki/Integer_%28computer_science%29

Worth a read and I'd use the number of bytes to indicate the specific integer used, e.g. int4 to indicate a 4-byte integer in order to prevent confusion.

One man's long could be another man's short
_________________________
There are two types of vessels, submarines and targets.

Top
#133714 - 2005-02-14 10:12 AM Re: Integers vs. Long Integers
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
KiXtart is not strongly typed, so the issue of integer size other than the maximum supported is only of minor interest. Your data and variables will be silently converted by context, which makes setting a type pretty pointless.

For example (ignoring signing for the present), say you have a variable "i" declared as a one byte integer.

In "C":
Code:
i=255+1


"i" now contains zero, as the expression has reached the size of the variable and the extra bits are dropped.

In KiXtart:
Code:
$i=255+1


"$i" now has the value 256. Even worse, it has been converted to a 2 or 4 byte integer so that it is large enough to store the result.

As another example, take a biwise NOT (not to be confused with KiXtarts logical NOT). A bitwise NOT simply reverses all the bits in an expression. Very useful for switching individual bits on and off amongst other things.

The problem is that without being able to assign a size to the expression, you can't determine the size of the result.

Should "NOT 0" be 255, 65535 or 4294967295?

Actually, that last one is even trickier as KiXtart does not support unsigned integers so &FFFFFFFF is "-1", which is a major pain.

The same problem occurs when you want to do a bitwise shift or roll - unless you can fix the size of the expression you are going to have problems, or you are going to have to code around it by explicitly passing the expression size as well as the expression.

There was a recent query on the board about converting a hash key generation algorithm to KiXtart. It is possible, but damned hard in part because of the lack of strongly typed data types.

I particularly miss being able to use unsigned types when it comes to network scripting - it's a bit of a coding nightmare when the values suddenly become negative.

Generally you can code around the problems, but it does make life difficult when trying to convert code from other languages where the (fixed) data size is a part of the coding technique.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 529 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.203 seconds in which 0.129 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org