YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

unsigned integer?
Rick
#1 Posted : Thursday, September 1, 2005 1:31:48 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/30/2005(UTC)
Posts: 26

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Are there any plans on adding an unsigned integer type?

In Lua all numbers were doubles by default, and I had no problem using them for numbers larger than 2147483647. There doesn't seem to be anything available for unsigned math so... :)
John Schultz
#2 Posted : Thursday, September 1, 2005 2:48:00 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/24/2005(UTC)
Posts: 241

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
A quick fix might be to recompile with OT_FLOAT as double or OT_INTEGER as __int64 (unless these types must be 4 bytes), much in the same way 16-bit chars can be used. Otherwise, a large int (123LL)  or double (123.d) might be useful additions.



John
serge
#3 Posted : Thursday, September 1, 2005 6:16:58 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/6/2005(UTC)
Posts: 22

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Unfortunately it will not work yet, see my explanation of the possible problems here: http://www.squirrel-lang.org/forums/158/ShowPost.aspx (too long post to copy here, just search for '<span id="PostFlatView">redefining type</span>' substring there). But fagiano said that he is working on fixing these issues, so hopefully it will be resolved in one of the next versions of squirrel  :)



As for unsigned integer, some standard library functions from squirrel make use of signed integers. But I agree that 32 bits is not enough, we need larger integers support for working with large files for example.
serge
#4 Posted : Thursday, September 1, 2005 6:33:54 AM(UTC)
Rank: Member

Groups: Registered
Joined: 7/6/2005(UTC)
Posts: 22

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Another idea might be to use new user defined type: 32-bit (or 64-bit) userdata with all the necessery operators for unsigned math defined. It will work slower than built-in types, but can provide some larger integers support.



Any volunteers for writing arbitrary big numbers library for squirrel? ;)


belbardonisakel
#5 Posted : Sunday, June 28, 2015 7:16:04 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/28/2015(UTC)
Posts: 9
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello Guys

i did it - squirrel language is unbeleavable.

I did a unsigned interer patch to the 3_0_7 stable version within some hours. This is definitely the only program language on this planet where this is possible.

Here a example how it's look like:

Code:

/*
   To declare an unsigned integer, prepend an u
   after the digits - works for hex, oct and int
*/

local myUHex = 0xFFFFu;
local myUOct = 0777u;
local myUInt = 1234u;

print("typeof hex: " + typeof(myUHex) + "\n");
print("typeof oct: " + typeof(myUOct) + "\n");
print("typeof oct: " + typeof(myUInt) + "\n");

print("You can change the types via tounsigned:\n");
print( 0xFFFFFFFF + "\n");
print( 0xFFFFFFFF.tounsigned() + "\n");

/* now try coparison */
print((0xFFFFFFFFu > 10) + "\n");
print((10 < 0xFFFFFFFFu) + "\n" );
print(format("The hex interpretation is the same: %04X, %04X\nbut comparison is different:\n",0xFFFFFFFFu,-1));
print((0xFFFFFFFFu != -1) + "\n");

/* now lets calculate */
print( 1u + 4u + 3u );

/* if ypu want to mix the things up - it will throw an exception */
try{
    local myuInt1 = 12u - 20;
    print("type is:" + typeof(myuInt1) + " val=" + myuInt1 + "\n");
} catch (e){
    print("EXPT: " + e + "\n");
}


Code:

typeof hex: unsigned
typeof oct: unsigned
typeof oct: unsigned
You can change the types via tounsigned:
-1
4294967295
true
true
The hex interpretation is the same: FFFFFFFF, FFFFFFFF
but comparison is different:
true
8EXPT: mixing up signed and unsigned integer


You will find the sources (diff) at my homepage belbardonisakel AT de.

Alberto: you did a really great peace of sourcecode man !!
brightening-eyes
#6 Posted : Saturday, September 26, 2015 5:09:48 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/21/2015(UTC)
Posts: 9
Man
Location: inside my computer

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
hi,
for integers, i think the best option is to use ptrdif_t which give's the largest possible amount of number which machine can hold
for float and double numbers, the best option is double
absence
#7 Posted : Saturday, September 26, 2015 11:42:48 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 105
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 9 time(s) in 9 post(s)
ptrdiff_t gives the size of a standard pointer. It is ONLY COINCIDENCE that a float or double, or an int USUALLY is the same size. It is definitely not of the same size on all architectures. I know Siemens MPUs that have 32bit pointers, but 16bit integers. I know MPUs that have 16 bit pointers but 32 bit floats. So be careful with that.
Maybe this makes it more understandable why there is an int, long int, and long long int. The long usually being one of the two others, but that's not necessarily always true.

(BTW: why are you talking about floats and doubles when this thread is about unsigned datatypes?)

However, in Squirrel, any unsigned integer datatype should match the SQInteger size. And if you look close at squirrels source, there IS an SQUnsignedInteger - it's just not used as a Squirrel datatype, but internally only. So he's better of using that than anything else ;-)

For me personally, I don't need unsigned integers as a Squirrel datatype. That's just a matter of representation, inside the CPU the math stays the exact same anyways. It's giving you an additional bit for positive numbers, that's all. Even worse, an unsigned representation incurs the problem any compiler will complain about: What happens if you do a comparison between a signed and unsigned integer? Just imagine this in squirrel (example is for 64 bit integers):

local foo=-99 ;
local bar=4611686018427387900u ;
if (foo < (bar+100)) print ("foo < bar+100") ;
if (foo < (100+bar)) print ("foo < 100+bar") ;

What is the result of bar+100 and what is the result of 100+bar? Or any combination of signed and unsigned math compared to whatever type? One of the two strings will be printed fer sure. Logically, this is not solveable without proper CASTING OR TYPE DECLARATION! (or additional math operators... BRRRR!!!!)
For a language with dynamic types this is probably a bad idea to introduce.

There may be reasons he is using unsigned integers, but I wouldn't add it to Squirrel in general.


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.148 seconds.