1210 / 100 = 12? what?

Sent: Friday, December 27, 2002 2:27 PM
To: ruby-talk@ruby-lang.org
Subject: Re: 1210 / 100 = 12? what?

no i didn’t realize that. i thought ruby would automatically
change it to a
float if need be, i.e. with divison, just as it changes to
Bignum if need be.

honestly i don’t like it. now i have to go around adding .0’s
all over the
place to make sure the math comes out right. and in some
places i have to do
things like multiple by 1.0 b/c certain values come from cgi
script variables
i have no control over.

(though I’m late in the thread) I’m in agreement. I like Ruby since it’s
supposed to be closer to our minds :wink:

When I scribble on a division, I should not be needing to append “.0” :frowning:

Com’on, I thought we’ve passed thru 3GL langs (I admit I still love fortran
and c, but I have to grow :-)…

I’d like to introduce the "" for integer division though :slight_smile:

well, it will suffice now that i know, but to me it is
definitely not POLS.

-tom

kind regards,
-botp

···

Tom Sawyer [mailto:transami@transami.net] wrote:

Hi.

···

At 01:23 PM 12/28/2002 +0900, botp wrote:

I’d like to introduce the "" for integer division though :slight_smile:

Or use the following:

Int: div mul mod
Float: / * (who cares)

And then we can over-load div and mul for rationals, fixed
point arithmetic and some complex number forms! Fun!

-mark. :wink:

This is one of the things where a statically typed language will do
the “right” thing but a dynamically typed language won’t. The #/
method returns a new reference to a Fixnum object, because only
Fixnums are known as the receiver and message object. C et al. will
silently and automatically convert the integers to floating point
values.

What I’d actually like to see (and in some ways, this is Perl
wantarray envy) is this:

(n, r) = 5 / 4 # n == 1, r == 1

In this way, I don’t have to do:

n = 5 / 4
r = 5 % 4

It may not be any more efficient, but it looks cleaner. Sort of.
Perhaps something like this could be done:

(n, r) = 5 // 4 # n == 1, r == 1

Introducing a new operator, #//.

I generally prefer integer or fixed-point operations over floating
point operations (greater accuracy at the cost of variable
precision), so I find them less surprising.

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.27 at 23.42.40

···

On Sat, 28 Dec 2002 13:23:24 +0900, Peña, Botp wrote:

Tom Sawyer [mailto:transami@transami.net] wrote:

no i didn’t realize that. i thought ruby would automatically
change it to a float if need be, i.e. with divison, just as it
changes to Bignum if need be.

honestly i don’t like it. now i have to go around adding .0’s all
over the place to make sure the math comes out right. and in some
places i have to do things like multiple by 1.0 b/c certain
values come from cgi script variables i have no control over.
(though I’m late in the thread) I’m in agreement. I like Ruby
since it’s supposed to be closer to our minds :wink:

When I scribble on a division, I should not be needing to append
“.0” :frowning:
Com’on, I thought we’ve passed thru 3GL langs (I admit I still
love fortran and c, but I have to grow :-)…

Then you want

n, r = 5.divmod(4)

which is there already :slight_smile:

Gavin

···

On Saturday, December 28, 2002, 3:52:42 PM, Austin wrote:

What I’d actually like to see (and in some ways, this is Perl
wantarray envy) is this:

(n, r) = 5 / 4 # n == 1, r == 1

In this way, I don’t have to do:

n = 5 / 4
r = 5 % 4