[Curious] Integer division => fraction

John W. Sarkela sarkela at sbcglobal.net
Wed Jun 11 23:29:04 UTC 2003


On Wednesday, June 11, 2003, at 03:01 PM, Andreas Raab wrote:

> Hi Guys,
>
> Just had an interesting discussion with Dean (over on e-Lang) about 
> integer
> division semantics. He pointed out (and I agree) that most people tend 
> to
> find it it confusing that "3/4" results in a fraction rather than 
> coercing
> to Float by default.

I have to say, I prefer exact answers to familiar looking 
approximations. In my book, information loss is something to be 
avoided. Then again, when I learned arithmetic there were no pocket 
calculators and one expected fractions as the result of integer 
arithmetic.

>
> My questions: What do you think about this issue? Are you personally
> surprised if you get a fraction back? Has it bitten you in unexpected
> places? Have you actually ever had the need for coercing to fractions
> instead of floats? Can you think of "typical" applications that would 
> be
> harmed by coercing to floats?
>

Finding that division of integers resulted in a rational was one of the 
most pleasant surprises of my programming experience. To me a rational 
number is the most natural result of division of integers.

The only issues that I have ever encountered were performance related. 
However, message tallies quickly pointed to where the time was being 
consumed. I have never had code break because of rational arithmetic.

I did work on an application that applied algebraic topology to logical 
models. It was essential to the process that one could express *exact* 
half open intervals. There were some very insidious and quite nasty 
bugs that occurred when some values were accidentally coerced to 
floats. By nature, this application was extraordinarily sensitive to 
boundary conditions. If your iterated function system is just drawing 
pictures, there is no great loss, when that system is making 
decisions... oh my, that is a very different matter indeed.

Cheers,
:-}> John Sarkela

Rings, Maximal ideals, and Ultra-filters... Oh my!

> Thanks for any info you can share.
>
> Cheers,
>   - Andreas
>



More information about the Squeak-dev mailing list