[#2367] Standard libraries — Dave Thomas <dave@...>

From ruby-dev summary:

60 messages 2004/02/11

[#2397] PATCH: deprecate cgi-lib, getopts, importenv, parsearg from standard library — Gavin Sinclair <gsinclair@...>

Index: cgi-lib.rb

15 messages 2004/02/12

[#2465] PATCH: OpenStruct#initialize to yield self — Gavin Sinclair <gsinclair@...>

This is a common approach I use to object initialization; I don't know

24 messages 2004/02/19

Problems in mathn, rational, complex, matrix

From: Gavin Sinclair <gsinclair@...>
Date: 2004-02-01 05:54:16 UTC
List: ruby-core #2320
I received a message from Richard Graham mentioning a problem in the
Matrix class.  Below is an extract.

--Gavin --------------------- 8< ----------------------------------


The stdlib documentation drew my attention with the Matrix
class example for determinant.

http://www.ruby-doc.org/stdlib/libdoc/matrix/rdoc/classes/Matrix.html#M000064

  Matrix[[7,6], [3,9]].determinant
    => 63

Call me a geek, but I instantly saw that this was the wrong
answer.  I think Ruby is great so I figured the documentation
must be in error.  To check, I tried it locally and was astonished
when I got the same wrong answer!  Say it isn't so!  8-O

After some investigation, the source of the immediate "problem"
is the statement:

       q = a[i][k] / akk

in the source code for the determinant.  With integer operands,
you get integer quotients.  Mayhem follows.

Further investigation shows that the "rational" library has
a "quo" method that fixes the above problem, but the alias
of "/" to "quo" only occurs in "mathn"!

It seems that the mathn, rational, complex, and matrix libraries
are not as orthogonal as one would expect.  I wish they were.

So, at present; rational, complex, and matrix libraries
should not be "required" unless the necessary functionality of
mathn is somehow maintained.  I did not investigate further so I
don't know what other traps await "requirers" of the individual
libraries.

Until the library source code is changed (will it ever?), it
seems users should be cautioned to just require 'mathn' to
ensure proper functionality.




In This Thread

Prev Next