From:

Date:

March 8, 2001 02:35Subject:

Re: [ID 20010305.005] "use integer" doesn't make rand() return integersMessage ID:

20010308103544.A7731@plum.flirble.orgOn Wed, Mar 07, 2001 at 07:10:17PM -0500, Bryan C . Warnock wrote: > On Wednesday 07 March 2001 18:08, abigail@foad.org wrote: > > Yes, but how useful is the floating point value of rand() in a "use > integer" > > context? As soon as you use it an arithmetic operation, including > comparison, > > it gets rounded. > > Er, truncated, I should think. No, floored. No, it doesn't seem to do > either. Or it does both. :-( Both arguments get truncated before any calculation It's not the "rounded" result of a floating point calculation. > #!/usr/bin/perl -w > @a = (-1.9, -1.1, -.9, -.1, .1, .9, 1.1, 1.9); > print "@a\n"; > @b = map { $_ - 1 } @a; > print "@b\n"; > { > use integer; > @c = map { $_ - 1 } @a; > print "@c\n"; > } > > [bryan@homer ~]$ perl -w round > -1.9 -1.1 -0.9 -0.1 0.1 0.9 1.1 1.9 > -2.9 -2.1 -1.9 -1.1 -0.9 -0.1 0.1 0.9 > -2 -2 -1 -1 -1 -1 0 0 > ^^ ^^ ? -1 -1 0 0 0 0 1 1 -1 -1 -1 -1 -1 -1 -1 -1 == == == == == == == == -2 -2 -1 -1 -1 -1 0 0 It's doing exactly what it means by "integer arithmetic" Maybe the pod needs an example. Nicholas ClarkThread Previous | Thread Next

- [ID 20010305.005] "use integer" doesn't make rand() return integers by fanf
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John L. Allen
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Walt Mankowski
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John L. Allen
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Tony Finch
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Ronald J Kimball
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
**Re: [ID 20010305.005] "use integer" doesn't make rand() return integers**by Nicholas Clark- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About