Graal Forums  

Go Back   Graal Forums > Development Forums > Tech Support
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-30-2006, 12:25 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Bitwise confusion

-1 >> 1 returns -1 instead of 2147483647.
Meanwhile, 1 << 31 returns -2147483648.
I'm trying to make a more efficient function for returning sign.

In a mathematical sense, you can return val!=0?val/abs(val):0
in a piecewise sense, you can do:
if (val > 0)
return 1;
if (val < 0)
return -1;
return 0;

But really, all I need to do is test the value of the highest bit.
Maybe a getSign function wouldn't be a bad idea because the bitwise ops don't preserve sign consistently.

Also,
i = 1;
i <<= 1;
is giving me i as 0 instead of 2.

However,
i = 1;
i = i << 1;
works.

Last edited by jake13jake; 10-30-2006 at 12:53 AM..
Reply With Quote
  #2  
Old 10-30-2006, 04:41 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
I'm pretty sure <<= isn't a valid operator. >_>
Reply With Quote
  #3  
Old 10-30-2006, 03:29 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
There was a bug with the shiftleft-assign, it was actually doing a shiftright-assign. Thanks for reporting, a new version of the npcserver will be uploaded soon.
Need to check the bit-operation to improve the compatibility with C-code.
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 11:14 PM.


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