ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> edu-sig
edu-sig
[Edu-sig] long int / long int = ??
by Brent Burley other posts by this author
Aug 3 2001 7:12PM messages near this date
Re: [Edu-sig] PythonScript | Re: [Edu-sig] long int / long int = ??
It has been noted that int/int=int results in more information loss than
int/int=float.  Based on this, it has been proposed that
anything/anything return float.  This got me wondering about long ints.

Given that a long int can have an unlimited number of digits (easily
into the thousands), the result of a long/long could also be an
unlimited number of digits (considering just the integer part).

Given that a float can only represent about a dozen or so digits of
precision, the precision loss due to float conversion could be much
greater than the precision loss due to dropping the fractional part of
the long division.  It's as if you're compressing an unlimited amount of
information into 8 bytes.

Also consider that float can only represent numbers up to about 1e308. 
Any result >  308 digits would result in a float "inf" - total
information loss.

I therefore argue that long int division should not result in a float.

There have been discussions about a unified numeric model for python. 
One suggestion is to automatically promote to long int on int overflow. 
If int/int=float and long/long=long, auto-promoting int to long could
cause strange and unpredictable results.  However, if a/b=float for all
types, this would be unfortunate for the long/long case for the reasons
mentioned.

Are rationals the answer?  They would provide zero information loss for
integer division and consistent behavior between integers, rationals,
and floats.  So, if rationals are coming, is int/int=float just a
stopgap?  Is it worth the pain?

	Brent

_______________________________________________
Edu-sig mailing list
Edu-sig@[...].org
http://mail.python.org/mailman/listinfo/edu-sig
Thread:
Brent Burley
Kirby Urner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved