1. INTEGER ???
- Posted by Bernie Ryan <bwryan at PCOM.NET>
Jul 14, 1999
-
Last edited Jul 15, 1999
Well I made another mistake and read the Library Document
Syntax: i = integer(x)
Description: Return 1 if x is an integer in the range -1073741824 to
+1073741823. Otherwise return 0.
Is this the correct SIZE for an Euphoria integer ?
Shouldn't the SIZE be:
range of -2,147,483,648 to +2,147,483,647 ( a 4 byte integer )
Bernie
2. Re: INTEGER ???
- Posted by Greg Harris <blackdog at CDC.NET>
Jul 14, 1999
-
Last edited Jul 15, 1999
Hi Bernie,
Euphoria integers are only 31 bits not 32 bits (4 bytes)..
I believe Rob uses bit 32 to check and see if it is a pointer (to an atom or
sequence) internally in the interpreter.
Hope I'm right :)
Regards,
Greg Harris
----- Original Message -----
From: Bernie Ryan <bwryan at PCOM.NET>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, July 14, 1999 8:19 PM
Subject: INTEGER ???
> Well I made another mistake and read the Library Document
>
> Syntax: i = integer(x)
>
> Description: Return 1 if x is an integer in the range -1073741824 to
> +1073741823. Otherwise return 0.
>
> Is this the correct SIZE for an Euphoria integer ?
>
> Shouldn't the SIZE be:
> range of -2,147,483,648 to +2,147,483,647 ( a 4 byte integer )
>
> Bernie
>
3. Re: INTEGER ???
Rob
If you are using 31 bits in an Euphoria integer, couldn't this cause a
compatibility problem when exchanging data with another external program
because the SIGN BIT does not comform to its standard position ?
Bernie
4. Re: INTEGER ???
>Rob
>If you are using 31 bits in an Euphoria integer, couldn't this cause a
>compatibility problem when exchanging data with another external program
>because the SIGN BIT does not comform to its standard position ?
>Bernie
Not really...
Euphoria has routines to automatically handle this sort of thing. You just
have to be sure to put the results into a variable of type atom, unless you
KNOW that the value will fit within the bounds for a Euphoria integer. For
example:
atom int32
integer int31
int32 = peek4s (ADDRESS_OF_32_BIT_SIGNED_INT)
-- now you can make use of the 32-bit integer value almost anywhere
int32 = bytes_to_int ({byte1, byte2, byte3, byte4})
-- this is the same thing, except from a sequence instead of from memory;
-- the "int" could be a 32-bit value, so it should be put into an atom
int31 = peek4u (ADDRESS_OF_PLAYER_SCORE_A_32_BIT_UNSIGNED_INT)
-- you could do this if player scores are limited to 0 through 999999
Use poke4() or int_to_bytes() to reverse the process. Other machine-level
routines let you convert between atoms and 32-bit floats, and between atoms
and 64-bit floats.
Rod
5. Re: INTEGER ???
>If you are using 31 bits in an Euphoria integer, couldn't this cause a
>compatibility problem when exchanging data with another external program
>because the SIGN BIT does not comform to its standard position ?
>Bernie
This only my speculation regarding how RDS handles integers, but I think
Euphoria integers will be values with bits 00 or 11 in the 31..32nd bit
positions.
Values starting with 00 can accomodate values
00000000000000000000000000000000b (0)
to
00111111111111111111111111111111b (1,073,741,823)
Values starting with 11 can accomodate values
11000000000000000000000000000000b (-1,073,741,824)
to
11111111111111111111111111111111b (-1)
^
sign bit is correct
Values starting with 01 or 10 might then be used to hold a index to some
atom or sequence structure.
Since the range of values that an integer can hold is 2^31, Rob correctly
states that it holds a 31-bit value. This not not mean that the integer
always uses the same 31 out of 32 bits at any given time. Since the
integers (within range) are stored the same way as external programs, with
the correct sign bit and be exchanged with C routines with no problems.
On the other hand, when Euphoria receives an 32-bit integer from an
external source, it must check whether or not it falls into the allowed
range for Euphoria 31-bit integers. If it doesn't fit, then it will be
converted into an atom. The fact that Euphoria does all this invisibly
and correctly can be considered magic.
As a side note, Peuphoria, my pet Euphoria interpreter written in C,
handles a slightly larger range of integers:
Positive values:
00000000000000000000000000000000b (0)
to
01111111111111111111111111111111b (2,147,483,647)
Negative values:
10000000000000000000000000000000b (-2,147,483,648)
to
11110111111111111111111111111111b (-134,217,729)
and
11111100000000000000000000000000b (-67,108,864)
to
11111111111111111111111111111111b (-1)
Which gives a range of 4,227,858,432 values, or a 31.97727992-bit
integer... Values in between -134,217,729 and -67,108,864 are reserved
for atom and sequence indices, but unfortunately Peu will not convert your
integers to atoms automatically so you have to watch out.
Later,
_______ ______ _______ ______
[ _ \[ _ ][ _ _ ][ _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
| ___/ | _] | | | _]
[\| [/] [\| [_/] [\| |/] [\| [_/]
[_____] [______] [_____] [______]
xseal at harborside.com ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/