[Numpy-discussion] Re: numpy, overflow, inf, ieee, and rich , comparison

Steven D. Majewski sdm7g at virginia.edu
Wed Oct 25 01:17:35 EDT 2000


On Wed, 25 Oct 2000, Donald O'Donnell wrote:

> Correct, that's called operator overloading, a form of polymorphism.
> I've seen postings in the past where someone has complained about
> the fact that 5/2 results in 2.  I can't, for the life of me
> understand why anyone would want it to be otherwise.  Every 
> main-stream language I've ever used (Fortran, COBOL, Basic,
> C, C++, Java,...) have all truncated the result of integer
> division to an integer, and that can be very useful. 

Well -- again those are all statically typed languages where 
variables have a fixed type. ( Not sure if modern Basics still
fit that catagory -- they did in the old days when I last used
Basic. ) 

Among dynamically typed languages, Lisp and Scheme return either
floats or rationals. Don't know offhand about Smalltalk.
I can't recall S+ and I don't know Matlab, but I would be surprised
if they didn't follow Lisp. 


>            				 Try writing
> a binary search (where you are constantly dividing your
> range by 2) -- not much fun if the interpreter/compiler keeps
> secretly changing your integer indexes to floats every time you 
> have an odd sized range.  If you really want a floating point
> result in the above example, all you need to do is use a/2.0 
> -- see, you are in control this way, not the compiler


It's not much fun it the interpreter/compiler keeps secretly 
truncating correct answers to incorrect ones every time your
args aren't evenly divisible. If you really wanted it truncated,
all you need to do is use floor/ceil/int. ( Works fine for binary
searches too! ) 


---|  Steven D. Majewski   (804-982-0831)  <sdm7g at Virginia.EDU>  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of Virginia             Health Sciences Center  |---
---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---
		"All operating systems want to be unix, 
		 All programming languages want to be lisp." 





More information about the Python-list mailing list