Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 03:06 AM.


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