Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-01-2008, 02:24 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Unsigned Bitshift

Hello all,

Since Stefan thought it would be hilarious to ignore my PM, I'll ask in here.

I'm trying to do a unsigned bitshift to the right (equiv of >>> in some other dynamically typed languages).

However, Graal does not provide any operator for this, nor a method to cast your signed integer to an unsigned integer.

I would also like to get past the max signed int value.

If anyone has experienced this problem before and has a solution, let me know!

Thanks
Reply With Quote
  #2  
Old 11-20-2008, 07:27 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
From what I know, Graal encodes the values as string-representations... So there is no true 'type' of variable. value = 12 and value = "12" is the same thing!

The best way to do the bit-shift is just... number = number >> 2;
This would work for unsigned values... And would do a bit-shift!

There is no special signed bit-shift around.

As for the max integer... Because values are numbers represented by strings... There is no real boundary.

You might want to look here for basic operators:
http://wiki.graal.net/index.php/Crea...uide#Operators
Reply With Quote
  #3  
Old 11-20-2008, 09:30 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
From what I know, Graal encodes the values as string-representations... So there is no true 'type' of variable. value = 12 and value = "12" is the same thing!

The best way to do the bit-shift is just... number = number >> 2;
This would work for unsigned values... And would do a bit-shift!

There is no special signed bit-shift around.

As for the max integer... Because values are numbers represented by strings... There is no real boundary.

You might want to look here for basic operators:
http://wiki.graal.net/index.php/Crea...uide#Operators
WhiteDragon is of sufficient skill to be able to tell if Graal has a max integer value or not. If he says he's hitting the limit then you should do a test for yourself right now before saying otherwise.
__________________
Reply With Quote
  #4  
Old 11-20-2008, 10:54 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Novo View Post
From what I know, Graal encodes the values as string-representations... So there is no true 'type' of variable. value = 12 and value = "12" is the same thing!

...

As for the max integer... Because values are numbers represented by strings... There is no real boundary.
Well, there is, because when you perform a mathematical operation on a string, it is converted from a string to a float/int internally so the same restrictions apply.
Reply With Quote
  #5  
Old 11-20-2008, 11:18 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Skyld double posting, epic moment.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #6  
Old 11-20-2008, 11:23 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by xXziroXx View Post
Skyld double posting, epic moment.
Shows how awesome my internet connection is.
Reply With Quote
  #7  
Old 11-20-2008, 11:39 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
If Graal could implement something like Python's long integer, then we could have infinitely sized numbers.
__________________
Reply With Quote
  #8  
Old 11-21-2008, 04:35 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Novo View Post
The best way to do the bit-shift is just... number = number >> 2;
This would work for unsigned values... And would do a bit-shift!
Sometimes you go over the max positive value and it "wraps around" to the lowest negative value. I guess this may have been why he also asked about getting past the max value.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #9  
Old 11-21-2008, 05:28 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Well, for those who are interested, I did get a reply from Stefan about a week ago (after PMing him again):
Quote:
Graal is using floating-point numbers (64 bit), for bit-wise operation it's converting to 32-bit signed integer and back to floating point. It could theoretically be possible to use 64-bit integers for that, for what kind of stuff do you need it?
However, he never responded to what I sent back to him.
And also, I think Stefan was talking about numbers on the server rather than on the client, because it would obviously be impossible to have a 64-bit integer on a 32-bit processor.

Even if the client did support 64-bit numbers, that isn't even what I'm looking for. I am specifically looking for an unsigned 32-bit integer, so I can make use of the overflow that is commonly used in many algorithms and hash functions.


And in reply to Inverness' post about Python's long integer, although having an arbitrary-precision arithmetic library would be useful, it would also be very slow because of the time complexity it takes to do arbitrary-precision operations.



Basically the only way I can pull off exactly what I'm trying to do is with direct access to unsigned 32-bit integers, not some slow pseudo-big-integer.

I can't think of any way to do this without Stefan intervening unless he has done so before and someone remembers how he said to do it.
Reply With Quote
  #10  
Old 11-21-2008, 05:49 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by WhiteDragon View Post
And in reply to Inverness' post about Python's long integer, although having an arbitrary-precision arithmetic library would be useful, it would also be very slow because of the time complexity it takes to do arbitrary-precision operations.
I don't think you'll find a more efficient implementation than Python's. And Python uses a trailing L to differentiate between the long object (arbitrary), and the int object (signed 32-bit).

Though in Python 3.0 the long object is being removed and the int object will behave as a long did. I'm sure this would not be done unless their implementation was efficient enough to warrant it. The source code is available for you to view on your own
__________________
Reply With Quote
  #11  
Old 11-21-2008, 06:13 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Inverness View Post
I don't think you'll find a more efficient implementation than Python's. And Python uses a trailing L to differentiate between the long object (arbitrary), and the int object (signed 32-bit).

Though in Python 3.0 the long object is being removed and the int object will behave as a long did. I'm sure this would not be done unless their implementation was efficient enough to warrant it. The source code is available for you to view on your own
It's not really a matter of "more efficient" when there is a upper bound on the mathematical model required to do arbitrary-precision operations.

Where two n-digit numbers:
Addition and subtraction take O(n)
For multiplication and division, they either use the Toom-Cook (O(n**1.465)) or Schonhage-Strassen (O(n * log n * log log n)) algorithm based on the size of the integer.

These are the accepted time complexities for arbitrary-precision operations, which makes certain algorithms horribly inefficient compared to doing the operations directly with the processor.


And in response to your "efficient enough to warrant it" comment, there is a reason that algorithms are coded in ASM and C++ rather than Python. When finer granularity is needed for something you wouldn't use a high-level language like Python.


However, something as simple as a unsigned bit-wise shift should be possible in GraalScript, which is why I'm inquiring Stefan.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.