0001-documentation-for-the-mathn-library.patch

Jason Dew, 05/13/2011 05:55 AM

Download (1.98 KB)

View differences:

lib/mathn.rb
1
##
2
# = mathn
1 3
#
2
#   mathn.rb -
3
#   	$Release Version: 0.5 $
4
#   	$Revision: 1.1.1.1.4.1 $
5
#   	by Keiju ISHITSUKA(SHL Japan Inc.)
4
# mathn is a library for changing the way Ruby does math.
6 5
#
7
# --
6
# == Usage
7
#
8
# To start using this library, simply:
9
#
10
#   require "mathn"
11
#
12
# This will change the way division works for Fixnums, specifically
8 13
#
14
#   3 / 2
9 15
#
16
# will return (3/2) instead of the usual 1.
10 17
#
18
# == Copyright
19
#
20
# Author: Keiju ISHITSUKA(SHL Japan Inc.)
21
#
22
# --
23
# $Release Version: 0.5 $
24
# $Revision: 1.1.1.1.4.1 $
11 25

  
12 26
require "cmath.rb"
13 27
require "matrix.rb"
......
27 41

  
28 42
  alias power! ** unless method_defined? :power!
29 43

  
44
  ##
45
  # exponentiate by +other+
30 46
  def ** (other)
31 47
    if self < 0 && other.round != other
32 48
      Complex(self, 0.0) ** other
......
43 59

  
44 60
  alias power! ** unless method_defined? :power!
45 61

  
62
  ##
63
  # exponentiate by +other+
46 64
  def ** (other)
47 65
    if self < 0 && other.round != other
48 66
      Complex(self, 0.0) ** other
......
119 137

  
120 138
module Math
121 139
  remove_method(:sqrt)
140

  
141
  ##
142
  # compute the square root of +a+
122 143
  def sqrt(a)
123 144
    if a.kind_of?(Complex)
124 145
      abs = sqrt(a.real*a.real + a.imag*a.imag)
......
144 165
    end
145 166
  end
146 167

  
147
  def rsqrt(a)
168
  def rsqrt(a) # :nodoc:
148 169
    if a.kind_of?(Float)
149 170
      sqrt!(a)
150 171
    elsif a.kind_of?(Rational)
......
199 220
class Float
200 221
  alias power! **
201 222

  
223
  ##
224
  # exponentiate by +other+
202 225
  def ** (other)
203 226
    if self < 0 && other.round != other
204 227
      Complex(self, 0.0) ** other
205
-