summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--doc/maintainers.rdoc2
-rw-r--r--doc/standard_library.rdoc1
-rw-r--r--lib/mathn.gemspec16
-rw-r--r--lib/mathn.rb167
-rw-r--r--test/bigdecimal/test_bigdecimal.rb6
-rw-r--r--test/ruby/test_array.rb4
-rw-r--r--test/ruby/test_enum.rb4
-rw-r--r--test/ruby/test_range.rb11
-rw-r--r--test/test_mathn.rb190
10 files changed, 3 insertions, 401 deletions
diff --git a/NEWS b/NEWS
index 3253e1f61a..cdb75cc7d9 100644
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,9 @@ with all sufficient information, see the ChangeLog file or Redmine
=== Stdlib compatibility issues (excluding feature bug fixes)
+* mathn.rb
+ Removed from stdlib. [Feature #10169]
+
=== C API updates
=== Supported platform changes
diff --git a/doc/maintainers.rdoc b/doc/maintainers.rdoc
index 0fe9e84520..476e587de5 100644
--- a/doc/maintainers.rdoc
+++ b/doc/maintainers.rdoc
@@ -70,8 +70,6 @@ Zachary Scott (zzak)
Keiju ISHITSUKA (keiju)
[lib/logger.rb]
Naotoshi Seo (sonots)
-[lib/mathn.rb]
- Keiju ISHITSUKA (keiju)
[lib/matrix.rb]
Marc-Andre Lafortune (marcandre)
[lib/mkmf.rb]
diff --git a/doc/standard_library.rdoc b/doc/standard_library.rdoc
index e13f280a22..a788080c72 100644
--- a/doc/standard_library.rdoc
+++ b/doc/standard_library.rdoc
@@ -25,7 +25,6 @@ GetoptLong:: Parse command line options similar to the GNU C getopt_long()
IPAddr:: Provides methods to manipulate IPv4 and IPv6 IP addresses
IRB:: Interactive Ruby command-line tool for REPL (Read Eval Print Loop)
Logger:: Provides a simple logging utility for outputting messages
-mathn.rb:: Deprecated library that extends math operations
MakeMakefile:: Module used to generate a Makefile for C extensions
Matrix:: Represents a mathematical matrix.
Monitor:: Provides an object or module to use safely by more than one thread
diff --git a/lib/mathn.gemspec b/lib/mathn.gemspec
deleted file mode 100644
index 3fbb466b8d..0000000000
--- a/lib/mathn.gemspec
+++ /dev/null
@@ -1,16 +0,0 @@
-Gem::Specification.new do |s|
- s.name = "mathn"
- s.version = '0.0.1'
- s.date = '2017-03-20'
- s.summary = "Deprecated library that extends math operations."
- s.description = "Deprecated library that extends math operations."
-
- s.require_path = %w{lib}
- s.files = %w{mathn.rb}
- s.required_ruby_version = ">= 2.5.0dev"
-
- s.authors = ["Keiju ISHITSUKA"]
- s.email = [nil]
- s.homepage = "https://www.ruby-lang.org"
- s.license = "BSD-2-Clause"
-end
diff --git a/lib/mathn.rb b/lib/mathn.rb
deleted file mode 100644
index 877559d269..0000000000
--- a/lib/mathn.rb
+++ /dev/null
@@ -1,167 +0,0 @@
-# frozen_string_literal: false
-#--
-# $Release Version: 0.5 $
-# $Revision: 1.1.1.1.4.1 $
-
-##
-# = mathn
-#
-# mathn serves to make mathematical operations more precise in Ruby
-# and to integrate other mathematical standard libraries.
-#
-# Without mathn:
-#
-# 3 / 2 => 1 # Integer
-#
-# With mathn:
-#
-# 3 / 2 => 3/2 # Rational
-#
-# mathn keeps value in exact terms.
-#
-# Without mathn:
-#
-# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18
-#
-# With mathn:
-#
-# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 20
-#
-#
-# When you require 'mathn', the libraries for Prime, CMath, Matrix and Vector
-# are also loaded.
-#
-# == Copyright
-#
-# Author: Keiju ISHITSUKA (SHL Japan Inc.)
-#--
-# class Numeric follows to make this documentation findable in a reasonable
-# location
-
-warn('lib/mathn.rb is deprecated') if $VERBOSE
-
-class Numeric; end
-
-require "cmath.rb"
-require "matrix.rb"
-require "prime.rb"
-
-unless defined?(Math.exp!)
- Object.instance_eval{remove_const :Math}
- Math = CMath # :nodoc:
-end
-
-##
-# When mathn is required, Integer's division is enhanced to
-# return more precise values from mathematical expressions.
-#
-# 2/3*3 # => 0
-# require 'mathn'
-# 2/3*3 # => 2
-#
-# (2**72) / ((2**70) * 3) # => 4/3
-
-class Integer
- remove_method :/
-
- ##
- # +/+ defines the Rational division for Bignum.
- #
- # (2**72) / ((2**70) * 3) # => 4/3
-
- alias / quo
-end
-
-##
-# When mathn is required, the Math module changes as follows:
-#
-# Standard Math module behaviour:
-# Math.sqrt(4/9) # => 0.0
-# Math.sqrt(4.0/9.0) # => 0.666666666666667
-# Math.sqrt(- 4/9) # => Errno::EDOM: Numerical argument out of domain - sqrt
-#
-# After require 'mathn', this is changed to:
-#
-# require 'mathn'
-# Math.sqrt(4/9) # => 2/3
-# Math.sqrt(4.0/9.0) # => 0.666666666666667
-# Math.sqrt(- 4/9) # => Complex(0, 2/3)
-
-module Math
- remove_method(:sqrt)
-
- ##
- # Computes the square root of +a+. It makes use of Complex and
- # Rational to have no rounding errors if possible.
- #
- # Math.sqrt(4/9) # => 2/3
- # Math.sqrt(- 4/9) # => Complex(0, 2/3)
- # Math.sqrt(4.0/9.0) # => 0.666666666666667
-
- def sqrt(a)
- if a.kind_of?(Complex)
- sqrt!(a)
- elsif a.respond_to?(:nan?) and a.nan?
- a
- elsif a >= 0
- rsqrt(a)
- else
- Complex(0,rsqrt(-a))
- end
- end
-
- ##
- # Compute square root of a non negative number. This method is
- # internally used by +Math.sqrt+.
-
- def rsqrt(a) # :nodoc:
- if a.kind_of?(Float)
- sqrt!(a)
- elsif a.kind_of?(Rational)
- rsqrt(a.numerator)/rsqrt(a.denominator)
- else
- src = a
- max = 2 ** 32
- byte_a = [src & 0xffffffff]
- # ruby's bug
- while (src >= max) and (src >>= 32)
- byte_a.unshift src & 0xffffffff
- end
-
- answer = 0
- main = 0
- side = 0
- for elm in byte_a
- main = (main << 32) + elm
- side <<= 16
- if answer != 0
- if main * 4 < side * side
- applo = main.div(side)
- else
- applo = ((sqrt!(side * side + 4 * main) - side)/2.0).to_i + 1
- end
- else
- applo = sqrt!(main).to_i + 1
- end
-
- while (x = (side + applo) * applo) > main
- applo -= 1
- end
- main -= x
- answer = (answer << 16) + applo
- side += applo * 2
- end
- if main == 0
- answer
- else
- sqrt!(a)
- end
- end
- end
-
- class << self
- remove_method(:sqrt)
- end
- module_function :sqrt
- module_function :rsqrt
-end
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 80ffc3fedd..7b720f4926 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -1765,12 +1765,6 @@ class TestBigDecimal < Test::Unit::TestCase
assert_kind_of(c, y)
end
- def test_to_d
- bug6093 = '[ruby-core:42969]'
- code = "exit(BigDecimal.new('10.0') == 10.0.to_d)"
- assert_ruby_status(%w[-rbigdecimal -rbigdecimal/util -rmathn -], code, bug6093)
- end
-
def test_bug6406
assert_in_out_err(%w[-rbigdecimal --disable-gems], <<-EOS, [], [])
Thread.current.keys.to_s
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index fbc0790f0f..d797ee8164 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2859,10 +2859,6 @@ class TestArray < Test::Unit::TestCase
assert_raise(TypeError) {[0].sum("")}
assert_raise(TypeError) {[1].sum("")}
-
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal(6, [1r, 2, 3r].sum)
- EOS
end
private
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index 27d406680a..f44d025c09 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -907,10 +907,6 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal("abc", ["a", "b", "c"].each.sum(""))
assert_equal([1, [2], 3], [[1], [[2]], [3]].each.sum([]))
-
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal(6, [1r, 2, 3r].each.sum)
- EOS
end
def test_hash_sum
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 1ce3f0663a..3743e9dda6 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -640,17 +640,6 @@ class TestRange < Test::Unit::TestCase
assert_raise(TypeError) { ("a".."z").bsearch {} }
end
- def test_bsearch_with_mathn
- assert_separately ['-r', 'mathn'], %q{
- msg = '[ruby-core:25740]'
- answer = (1..(1 << 100)).bsearch{|x|
- assert_predicate(x, :integer?, msg)
- x >= 42
- }
- assert_equal(42, answer, msg)
- }, ignore_stderr: true
- end
-
def test_each_no_blockarg
a = "a"
def a.upto(x, e, &b)
diff --git a/test/test_mathn.rb b/test/test_mathn.rb
deleted file mode 100644
index eb93895010..0000000000
--- a/test/test_mathn.rb
+++ /dev/null
@@ -1,190 +0,0 @@
-# frozen_string_literal: false
-require 'test/unit'
-
-# mathn redefines too much. It must be isolated to child processes.
-class TestMathn < Test::Unit::TestCase
- def test_power
- stderr = $VERBOSE ? ["lib/mathn.rb is deprecated"] : []
- assert_in_out_err ['-r', 'mathn', '-e', 'a=1**2;!a'], "", [], stderr, '[ruby-core:25740]'
- assert_in_out_err ['-r', 'mathn', '-e', 'a=(1 << 126)**2;!a'], "", [], stderr, '[ruby-core:25740]'
- end
-
- def test_quo
- stderr = $VERBOSE ? ["lib/mathn.rb is deprecated"] : []
- assert_in_out_err ['-r', 'mathn'], <<-EOS, %w(OK), stderr, '[ruby-core:41575]'
- 1.quo(2); puts :OK
- EOS
- end
-
- def test_floor
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal( 2, ( 13/5).floor)
- assert_equal( 2, ( 5/2).floor)
- assert_equal( 2, ( 12/5).floor)
- assert_equal(-3, (-12/5).floor)
- assert_equal(-3, ( -5/2).floor)
- assert_equal(-3, (-13/5).floor)
-
- assert_equal( 2, ( 13/5).floor(0))
- assert_equal( 2, ( 5/2).floor(0))
- assert_equal( 2, ( 12/5).floor(0))
- assert_equal(-3, (-12/5).floor(0))
- assert_equal(-3, ( -5/2).floor(0))
- assert_equal(-3, (-13/5).floor(0))
-
- assert_equal(( 13/5), ( 13/5).floor(2))
- assert_equal(( 5/2), ( 5/2).floor(2))
- assert_equal(( 12/5), ( 12/5).floor(2))
- assert_equal((-12/5), (-12/5).floor(2))
- assert_equal(( -5/2), ( -5/2).floor(2))
- assert_equal((-13/5), (-13/5).floor(2))
- EOS
- end
-
- def test_ceil
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal( 3, ( 13/5).ceil)
- assert_equal( 3, ( 5/2).ceil)
- assert_equal( 3, ( 12/5).ceil)
- assert_equal(-2, (-12/5).ceil)
- assert_equal(-2, ( -5/2).ceil)
- assert_equal(-2, (-13/5).ceil)
-
- assert_equal( 3, ( 13/5).ceil(0))
- assert_equal( 3, ( 5/2).ceil(0))
- assert_equal( 3, ( 12/5).ceil(0))
- assert_equal(-2, (-12/5).ceil(0))
- assert_equal(-2, ( -5/2).ceil(0))
- assert_equal(-2, (-13/5).ceil(0))
-
- assert_equal(( 13/5), ( 13/5).ceil(2))
- assert_equal(( 5/2), ( 5/2).ceil(2))
- assert_equal(( 12/5), ( 12/5).ceil(2))
- assert_equal((-12/5), (-12/5).ceil(2))
- assert_equal(( -5/2), ( -5/2).ceil(2))
- assert_equal((-13/5), (-13/5).ceil(2))
- EOS
- end
-
- def test_truncate
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal( 2, ( 13/5).truncate)
- assert_equal( 2, ( 5/2).truncate)
- assert_equal( 2, ( 12/5).truncate)
- assert_equal(-2, (-12/5).truncate)
- assert_equal(-2, ( -5/2).truncate)
- assert_equal(-2, (-13/5).truncate)
-
- assert_equal( 2, ( 13/5).truncate(0))
- assert_equal( 2, ( 5/2).truncate(0))
- assert_equal( 2, ( 12/5).truncate(0))
- assert_equal(-2, (-12/5).truncate(0))
- assert_equal(-2, ( -5/2).truncate(0))
- assert_equal(-2, (-13/5).truncate(0))
-
- assert_equal(( 13/5), ( 13/5).truncate(2))
- assert_equal(( 5/2), ( 5/2).truncate(2))
- assert_equal(( 12/5), ( 12/5).truncate(2))
- assert_equal((-12/5), (-12/5).truncate(2))
- assert_equal(( -5/2), ( -5/2).truncate(2))
- assert_equal((-13/5), (-13/5).truncate(2))
- EOS
- end
-
- def test_round
- assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
- assert_equal( 3, ( 13/5).round)
- assert_equal( 3, ( 5/2).round)
- assert_equal( 2, ( 12/5).round)
- assert_equal(-2, (-12/5).round)
- assert_equal(-3, ( -5/2).round)
- assert_equal(-3, (-13/5).round)
-
- assert_equal( 3, ( 13/5).round(0))
- assert_equal( 3, ( 5/2).round(0))
- assert_equal( 2, ( 12/5).round(0))
- assert_equal(-2, (-12/5).round(0))
- assert_equal(-3, ( -5/2).round(0))
- assert_equal(-3, (-13/5).round(0))
-
- assert_equal(( 13/5), ( 13/5).round(2))
- assert_equal(( 5/2), ( 5/2).round(2))
- assert_equal(( 12/5), ( 12/5).round(2))
- assert_equal((-12/5), (-12/5).round(2))
- assert_equal(( -5/2), ( -5/2).round(2))
- assert_equal((-13/5), (-13/5).round(2))
-
- assert_equal( 3, ( 13/5).round(half: :even))
- assert_equal( 2, ( 5/2).round(half: :even))
- assert_equal( 2, ( 12/5).round(half: :even))
- assert_equal(-2, (-12/5).round(half: :even))
- assert_equal(-2, ( -5/2).round(half: :even))
- assert_equal(-3, (-13/5).round(half: :even))
-
- assert_equal( 3, ( 13/5).round(0, half: :even))
- assert_equal( 2, ( 5/2).round(0, half: :even))
- assert_equal( 2, ( 12/5).round(0, half: :even))
- assert_equal(-2, (-12/5).round(0, half: :even))
- assert_equal(-2, ( -5/2).round(0, half: :even))
- assert_equal(-3, (-13/5).round(0, half: :even))
-
- assert_equal(( 13/5), ( 13/5).round(2, half: :even))
- assert_equal(( 5/2), ( 5/2).round(2, half: :even))
- assert_equal(( 12/5), ( 12/5).round(2, half: :even))
- assert_equal((-12/5), (-12/5).round(2, half: :even))
- assert_equal(( -5/2), ( -5/2).round(2, half: :even))
- assert_equal((-13/5), (-13/5).round(2, half: :even))
-
- assert_equal( 3, ( 13/5).round(half: :up))
- assert_equal( 3, ( 5/2).round(half: :up))
- assert_equal( 2, ( 12/5).round(half: :up))
- assert_equal(-2, (-12/5).round(half: :up))
- assert_equal(-3, ( -5/2).round(half: :up))
- assert_equal(-3, (-13/5).round(half: :up))
-
- assert_equal( 3, ( 13/5).round(0, half: :up))
- assert_equal( 3, ( 5/2).round(0, half: :up))
- assert_equal( 2, ( 12/5).round(0, half: :up))
- assert_equal(-2, (-12/5).round(0, half: :up))
- assert_equal(-3, ( -5/2).round(0, half: :up))
- assert_equal(-3, (-13/5).round(0, half: :up))
-
- assert_equal(( 13/5), ( 13/5).round(2, half: :up))
- assert_equal(( 5/2), ( 5/2).round(2, half: :up))
- assert_equal(( 12/5), ( 12/5).round(2, half: :up))
- assert_equal((-12/5), (-12/5).round(2, half: :up))
- assert_equal(( -5/2), ( -5/2).round(2, half: :up))
- assert_equal((-13/5), (-13/5).round(2, half: :up))
-
- assert_equal( 3, ( 13/5).round(half: :down))
- assert_equal( 2, ( 5/2).round(half: :down))
- assert_equal( 2, ( 12/5).round(half: :down))
- assert_equal(-2, (-12/5).round(half: :down))
- assert_equal(-2, ( -5/2).round(half: :down))
- assert_equal(-3, (-13/5).round(half: :down))
-
- assert_equal( 3, ( 13/5).round(0, half: :down))
- assert_equal( 2, ( 5/2).round(0, half: :down))
- assert_equal( 2, ( 12/5).round(0, half: :down))
- assert_equal(-2, (-12/5).round(0, half: :down))
- assert_equal(-2, ( -5/2).round(0, half: :down))
- assert_equal(-3, (-13/5).round(0, half: :down))
-
- assert_equal(( 13/5), ( 13/5).round(2, half: :down))
- assert_equal(( 5/2), ( 5/2).round(2, half: :down))
- assert_equal(( 12/5), ( 12/5).round(2, half: :down))
- assert_equal((-12/5), (-12/5).round(2, half: :down))
- assert_equal(( -5/2), ( -5/2).round(2, half: :down))
- assert_equal((-13/5), (-13/5).round(2, half: :down))
- EOS
- end
-
- def test_rational
- assert_separately(%w[-rmathn], "#{<<-"begin;"}\n#{<<-"end;"}", ignore_stderr: true)
- begin;
- assert_equal(-5, "-5".to_r)
- assert_equal(1, "5/5".to_r)
- assert_equal(5, "5e0".to_r)
- end;
- end
-end