* 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
This commit is contained in:
drbrain 2011-05-12 21:51:41 +00:00
parent f154226900
commit 6e10135d47
2 changed files with 36 additions and 8 deletions

View File

@ -1,3 +1,8 @@
Fri May 13 06:50:43 2011 Eric Hodel <drbrain@segment7.net>
* lib/mathn.rb: Add documentation. Patch by Jason Dew. [Ruby 1.9 -
Feature #4667]
Fri May 13 05:44:19 2011 Eric Hodel <drbrain@segment7.net> Fri May 13 05:44:19 2011 Eric Hodel <drbrain@segment7.net>
* lib/logger.rb (class Logger): Document Logger#datetime_format. * lib/logger.rb (class Logger): Document Logger#datetime_format.

View File

@ -1,13 +1,27 @@
##
# = mathn
# #
# mathn.rb - # mathn is a library for changing the way Ruby does math.
# $Release Version: 0.5 $ #
# $Revision: 1.1.1.1.4.1 $ # == Usage
# by Keiju ISHITSUKA(SHL Japan Inc.) #
# 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 "cmath.rb"
require "matrix.rb" require "matrix.rb"
@ -27,6 +41,8 @@ class Fixnum
alias power! ** unless method_defined? :power! alias power! ** unless method_defined? :power!
##
# exponentiate by +other+
def ** (other) def ** (other)
if self < 0 && other.round != other if self < 0 && other.round != other
Complex(self, 0.0) ** other Complex(self, 0.0) ** other
@ -43,6 +59,8 @@ class Bignum
alias power! ** unless method_defined? :power! alias power! ** unless method_defined? :power!
##
# exponentiate by +other+
def ** (other) def ** (other)
if self < 0 && other.round != other if self < 0 && other.round != other
Complex(self, 0.0) ** other Complex(self, 0.0) ** other
@ -119,6 +137,9 @@ end
module Math module Math
remove_method(:sqrt) remove_method(:sqrt)
##
# compute the square root of +a+
def sqrt(a) def sqrt(a)
if a.kind_of?(Complex) if a.kind_of?(Complex)
abs = sqrt(a.real*a.real + a.imag*a.imag) abs = sqrt(a.real*a.real + a.imag*a.imag)
@ -144,7 +165,7 @@ module Math
end end
end end
def rsqrt(a) def rsqrt(a) # :nodoc:
if a.kind_of?(Float) if a.kind_of?(Float)
sqrt!(a) sqrt!(a)
elsif a.kind_of?(Rational) elsif a.kind_of?(Rational)
@ -199,6 +220,8 @@ end
class Float class Float
alias power! ** alias power! **
##
# exponentiate by +other+
def ** (other) def ** (other)
if self < 0 && other.round != other if self < 0 && other.round != other
Complex(self, 0.0) ** other Complex(self, 0.0) ** other