9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] fun question
@ 2009-01-22 20:53 ron minnich
  2009-01-22 21:40 ` erik quanstrom
  2009-01-22 22:01 ` Russ Cox
  0 siblings, 2 replies; 8+ messages in thread
From: ron minnich @ 2009-01-22 20:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 20:53 [9fans] fun question ron minnich
@ 2009-01-22 21:40 ` erik quanstrom
  2009-01-22 22:01 ` Russ Cox
  1 sibling, 0 replies; 8+ messages in thread
From: erik quanstrom @ 2009-01-22 21:40 UTC (permalink / raw)
  To: 9fans

On Thu Jan 22 15:55:09 EST 2009, rminnich@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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 20:53 [9fans] fun question ron minnich
  2009-01-22 21:40 ` erik quanstrom
@ 2009-01-22 22:01 ` Russ Cox
  2009-01-22 22:12   ` Pietro Gagliardi
  1 sibling, 1 reply; 8+ messages in thread
From: Russ Cox @ 2009-01-22 22:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Jan 22, 2009 at 12:53 PM, ron minnich <rminnich@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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 22:01 ` Russ Cox
@ 2009-01-22 22:12   ` Pietro Gagliardi
  2009-01-22 22:54     ` Russ Cox
  0 siblings, 1 reply; 8+ messages in thread
From: Pietro Gagliardi @ 2009-01-22 22:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

-----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-----



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 22:12   ` Pietro Gagliardi
@ 2009-01-22 22:54     ` Russ Cox
  2009-01-22 23:01       ` erik quanstrom
  0 siblings, 1 reply; 8+ messages in thread
From: Russ Cox @ 2009-01-22 22:54 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>> <- is a unary operator.

> okay, what does it do? (unless you meant -> in C++)

it receives from a channel.

russ


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 22:54     ` Russ Cox
@ 2009-01-22 23:01       ` erik quanstrom
  2009-01-22 23:17         ` ron minnich
  2009-01-23  0:46         ` Pietro Gagliardi
  0 siblings, 2 replies; 8+ messages in thread
From: erik quanstrom @ 2009-01-22 23:01 UTC (permalink / raw)
  To: 9fans

On Thu Jan 22 17:55:55 EST 2009, rsc@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 = 1<<31;
	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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 23:01       ` erik quanstrom
@ 2009-01-22 23:17         ` ron minnich
  2009-01-23  0:46         ` Pietro Gagliardi
  1 sibling, 0 replies; 8+ messages in thread
From: ron minnich @ 2009-01-22 23:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] fun question
  2009-01-22 23:01       ` erik quanstrom
  2009-01-22 23:17         ` ron minnich
@ 2009-01-23  0:46         ` Pietro Gagliardi
  1 sibling, 0 replies; 8+ messages in thread
From: Pietro Gagliardi @ 2009-01-23  0:46 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

-----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-----



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-01-23  0:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-22 20:53 [9fans] fun question ron minnich
2009-01-22 21:40 ` erik quanstrom
2009-01-22 22:01 ` Russ Cox
2009-01-22 22:12   ` Pietro Gagliardi
2009-01-22 22:54     ` Russ Cox
2009-01-22 23:01       ` erik quanstrom
2009-01-22 23:17         ` ron minnich
2009-01-23  0:46         ` Pietro Gagliardi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).