How do I check if 2 numbers are oppositely signed in C++

Started by
39 comments, last by executor_2k2 22 years, 2 months ago
quote:Original post by a person
BigNumber implementations would HAVE to implement the operators that you were using (such as xor) or it would not compile at all. if the BigNumber implementation actually works the way it is supposed (actually treating it as a varible sized number where the number of bits can be anything) then by IEEE standards (like said before) requires the MSB to be 1 for negative numbers.

Which IEEE standard governs integer arithmetic?

quote:now no matter HOW mny bits are allocated for the BigNumber, in order to handle xor proberly the implemnetation woudl have to extend the smaller number to have the same number of bits as the larger one. which would place the MSB in the same bit location in both numbers thus properly working with the xor method. though it probally would be better to have a seperate function for bignumbers since they are not a atomic type to begin with and you could take advantage of how the numbers are stored (ie in the struct where the sign is located). if the BigNUmber implemnetation does not handle xor, then it simply wont compile, if it handles it incorrectly (by not extending the smaller number) then its the implemnetation thats buggy. this is why i said to use the if method since it will ALWAYS work assuming you dont do stupid things like pass unsigned numbers since in that case you are using the function wrong and it wont work anyway.

The BigNumber could be signed magnitude, in which case not one of the MSB, the LSB, nor any of the bits in between, would store the sign.

The BigNumber could be one's complement, in which case it would have representations for both positive and negative zero.


Edit: zero != infinity


Edited by - DrPizza on February 6, 2002 8:54:39 PM
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/

This topic is closed to new replies.

Advertisement