summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-12 21:51:41 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-12 21:51:41 +0000
commit6e10135d47a33975ee2c9d597caa968ce1045cb0 (patch)
tree6a7a50ce96999a16cbbbe9894961259967e29cf2 /lib
parentf154226900b258f6f51b328fab98becd6c23f5f7 (diff)
* lib/mathn.rb: Add documentation. Patch by Jason Dew. [Ruby 1.9 -
Feature #4667] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/mathn.rb35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 716b48602d..618f82077b 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -1,13 +1,27 @@
+##
+# = mathn
#
-# mathn.rb -
-# $Release Version: 0.5 $
-# $Revision: 1.1.1.1.4.1 $
-# by Keiju ISHITSUKA(SHL Japan Inc.)
+# mathn is a library for changing the way Ruby does math.
#
-# --
+# == Usage
+#
+# To start using this library, simply:
+#
+# require "mathn"
+#
+# This will change the way division works for Fixnums, specifically
#
+# 3 / 2
#
+# will return (3/2) instead of the usual 1.
#
+# == Copyright
+#
+# Author: Keiju ISHITSUKA(SHL Japan Inc.)
+#
+# --
+# $Release Version: 0.5 $
+# $Revision: 1.1.1.1.4.1 $
require "cmath.rb"
require "matrix.rb"
@@ -27,6 +41,8 @@ class Fixnum
alias power! ** unless method_defined? :power!
+ ##
+ # exponentiate by +other+
def ** (other)
if self < 0 && other.round != other
Complex(self, 0.0) ** other
@@ -43,6 +59,8 @@ class Bignum
alias power! ** unless method_defined? :power!
+ ##
+ # exponentiate by +other+
def ** (other)
if self < 0 && other.round != other
Complex(self, 0.0) ** other
@@ -119,6 +137,9 @@ end
module Math
remove_method(:sqrt)
+
+ ##
+ # compute the square root of +a+
def sqrt(a)
if a.kind_of?(Complex)
abs = sqrt(a.real*a.real + a.imag*a.imag)
@@ -144,7 +165,7 @@ module Math
end
end
- def rsqrt(a)
+ def rsqrt(a) # :nodoc:
if a.kind_of?(Float)
sqrt!(a)
elsif a.kind_of?(Rational)
@@ -199,6 +220,8 @@ end
class Float
alias power! **
+ ##
+ # exponentiate by +other+
def ** (other)
if self < 0 && other.round != other
Complex(self, 0.0) ** other