mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/mathn.rb: Improve documentation and attach it to Numeric.
Modified from patch by Anil V. [Ruby 1.9 - Bug #4762] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b6dd727b86
commit
5dcb4fc18b
2 changed files with 43 additions and 36 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jun 1 09:26:05 2011 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/mathn.rb: Improve documentation and attach it to Numeric.
|
||||
Modified from patch by Anil V. [Ruby 1.9 - Bug #4762]
|
||||
|
||||
Wed Jun 1 09:21:30 2011 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/prime.rb: Indent examples enough to appear as code sections.
|
||||
|
|
46
lib/mathn.rb
46
lib/mathn.rb
|
@ -1,42 +1,44 @@
|
|||
#--
|
||||
# $Release Version: 0.5 $
|
||||
# $Revision: 1.1.1.1.4.1 $
|
||||
|
||||
##
|
||||
# = mathn
|
||||
#
|
||||
# mathn is a library for changing the way Ruby does math. If you need
|
||||
# more precise rounding with multiple division or exponentiation
|
||||
# operations, then mathn is the right tool. It makes sense to use this
|
||||
# library if you can use it's late rounding. Mathn does not convert
|
||||
# Fixnums into Floats as long as you do not convert it yourself.
|
||||
# Instead of using Float as intermediate value it use Rational as
|
||||
# value representation.
|
||||
# operations, then mathn is the right tool.
|
||||
#
|
||||
# Example Fixnum with intermediate Float:
|
||||
# Without mathn:
|
||||
#
|
||||
# 3 / 2 => 1 # Integer
|
||||
#
|
||||
# With mathn:
|
||||
#
|
||||
# 3 / 2 => 3/2 # Rational
|
||||
#
|
||||
# mathn features late rounding and lacks truncation of intermediate results:
|
||||
#
|
||||
# Without mathn:
|
||||
#
|
||||
# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18
|
||||
#
|
||||
# Example: using mathn Fixnum/Rational:
|
||||
# With mathn:
|
||||
#
|
||||
# require 'mathn'
|
||||
# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 20
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# To start using this library, simply:
|
||||
#
|
||||
# require "mathn"
|
||||
#
|
||||
# This will change the way division works for Fixnums, specifically
|
||||
#
|
||||
# 3 / 2
|
||||
#
|
||||
# will return +Rational+ (3/2) instead of the usual +Fixnum+ 1.
|
||||
# When you require 'mathn' the libraries for Prime, CMath, Matrix and Vector
|
||||
# are also loaded.
|
||||
#
|
||||
# == Copyright
|
||||
#
|
||||
# Author: Keiju ISHITSUKA(SHL Japan Inc.)
|
||||
#
|
||||
# Author: Keiju ISHITSUKA (SHL Japan Inc.)
|
||||
#--
|
||||
# $Release Version: 0.5 $
|
||||
# $Revision: 1.1.1.1.4.1 $
|
||||
# class Numeric follows to make this documentation findable in a reasonable
|
||||
# location
|
||||
|
||||
class Numeric; end
|
||||
|
||||
require "cmath.rb"
|
||||
require "matrix.rb"
|
||||
|
|
Loading…
Reference in a new issue