[9fans] fun question
I ask this every time I hit this piece of code, I think. But what the heck: if(seed - 0) seed = seed + m_31; what's wrong with this code? ron
Re: [9fans] fun question
On Thu Jan 22 15:55:09 EST 2009, rminn...@gmail.com wrote: I ask this every time I hit this piece of code, I think. But what the heck: if(seed - 0) seed = seed + m_31; what's wrong with this code? supposing the code does what it is supposed to on some machines, i would guess that this could be a problem for sign-magnitude or one's-comp. machines, since 0 and -0 are different. if that's the case, one would guess that the object is to clear sign bit and -0 is the failure case. then again, that's a very wild guess and one would assume that sign = -sign would be better. -0 is a strange construction and the spacing is misleading. it's interesting that atoi(2) and the differ on - 0. - erik
Re: [9fans] fun question
On Thu, Jan 22, 2009 at 12:53 PM, ron minnich rminn...@gmail.com wrote: I ask this every time I hit this piece of code, I think. But what the heck: if(seed - 0) seed = seed + m_31; what's wrong with this code? - is a unary operator. russ
Re: [9fans] fun question
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Jan 22, 2009, at 5:01 PM, Russ Cox wrote: - is a unary operator. okay, what does it do? (unless you meant - in C++) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkl47zYACgkQuv7AVNQDs+wr7ACgi7QtQv4m4TweJlyzLFSHUs41 ZCYAnR6CqXQp69/g99pUkI0W789SRxXF =s97M -END PGP SIGNATURE-
Re: [9fans] fun question
- is a unary operator. okay, what does it do? (unless you meant - in C++) it receives from a channel. russ
Re: [9fans] fun question
On Thu Jan 22 17:55:55 EST 2009, r...@swtch.com wrote: - is a unary operator. okay, what does it do? (unless you meant - in C++) it receives from a channel. i assumed that ron was talking about c. in c, - 0 tokenizes as , -, and 0. - is taken to be a unary operator on 0. even gcc does this correctly: ; cat x.c #include u.h #include libc.h void x(int seed) { int m_31; m_31 = 131; if(seed - 0) seed = seed + m_31; print(seed %d\n, seed); } void main(void) { x(-5); exits(); } eot; 9c x.c ; 9l x.o ; ./a.out seed -2147483648 - erik
Re: [9fans] fun question
Erik got it. That code originally was written for a 1s complement machine, the CDC 7200 I believe. I get a kick out of it every time I see something and remember machines with + and - 0 :-) ron
Re: [9fans] fun question
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Jan 22, 2009, at 6:01 PM, erik quanstrom wrote: i assumed that ron was talking about c. Yeah, that's what I thought. Sorry, Russ. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkl5E1IACgkQuv7AVNQDs+xctgCggzbkwZ8EpuuEPu7e5kgItuC5 vDgAnisvoB6CWTOrPaXQ04jqyRL2kuJV =Yw+A -END PGP SIGNATURE-