ruby-units 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -10
- data/VERSION +1 -1
- data/lib/ruby_units/math.rb +1 -3
- data/lib/ruby_units/unit.rb +24 -20
- data/ruby-units.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448201b21f6913329bfbd81fff22ea949e74ba81
|
4
|
+
data.tar.gz: 1021947fecb0fbd41a2cda3dcce5d1a16a31cf61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e1a0a5ff0bf2c7cad7313296f1be2cf666394be7697e82ef0daf8c0d15ce8973ba2a9c4a40589d7bbdf381d5665fc71f237547ef6e10e19303e45fb36457c1
|
7
|
+
data.tar.gz: 5a41f0e985f8cc118674a29e64fc8b66b9c0cebd81bc622f4986469b0c5fe994c7276204fe1fcd87c81d63ce1e681d8a12f46ded7057f0f127b94ed56f185879
|
data/README.md
CHANGED
@@ -7,6 +7,13 @@ Kevin C. Olbrich, Ph.D.
|
|
7
7
|
|
8
8
|
Project page: [http://github.com/olbrich/ruby-units](http://github.com/olbrich/ruby-units)
|
9
9
|
|
10
|
+
Notes
|
11
|
+
-----
|
12
|
+
|
13
|
+
This version removes 'mathn' as a dependency. Mathn alters the behavior of some mathematical operators, which
|
14
|
+
frequently causes unexpected behavior and can be a source of difficult to diagnose bugs. Mathn is also scheduled to be removed from
|
15
|
+
the Ruby standard library.
|
16
|
+
|
10
17
|
Introduction
|
11
18
|
------------
|
12
19
|
|
@@ -276,16 +283,6 @@ Currently there is only one configuration you can set:
|
|
276
283
|
|
277
284
|
### NOTES
|
278
285
|
|
279
|
-
#### Mathn
|
280
|
-
|
281
|
-
Note that the current implementation of ruby-units requires 'mathn' from the ruby standard library.
|
282
|
-
This tends to change the behavior of integer math in ways that many people do not expect, and can be the source
|
283
|
-
of numerous bugs and odd behaviors. If you encounter what appears to be a bug in your code that seems to be related
|
284
|
-
|
285
|
-
to the use of ruby-units, try to reproduce the bug by just including 'mathn' by itself.
|
286
|
-
|
287
|
-
If you identify a bug in a gem or code that uses mathn, please file a bug report or create a pull request to fix it.
|
288
|
-
|
289
286
|
#### Performance vs. Accuracy
|
290
287
|
|
291
288
|
Ruby units was originally intended to provide a robust and accurate way to do arbitrary unit conversions.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/lib/ruby_units/math.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mathn'
|
2
|
-
|
3
1
|
# Math will convert unit objects to radians and then attempt to use the value for
|
4
2
|
# trigonometric functions.
|
5
3
|
module Math
|
@@ -100,7 +98,7 @@ module Math
|
|
100
98
|
# @return [Numeric]
|
101
99
|
def hypot(x, y)
|
102
100
|
if RubyUnits::Unit === x && RubyUnits::Unit === y
|
103
|
-
(x**2 + y**2)**(1
|
101
|
+
(x**2 + y**2)**Rational(1, 2)
|
104
102
|
else
|
105
103
|
unit_hypot(x, y)
|
106
104
|
end
|
data/lib/ruby_units/unit.rb
CHANGED
@@ -587,23 +587,23 @@ module RubyUnits
|
|
587
587
|
|
588
588
|
num = []
|
589
589
|
den = []
|
590
|
-
q = 1
|
591
|
-
@numerator.compact.each do |
|
592
|
-
if @@prefix_values[
|
593
|
-
q *= @@prefix_values[
|
590
|
+
q = Rational(1)
|
591
|
+
@numerator.compact.each do |num_unit|
|
592
|
+
if @@prefix_values[num_unit]
|
593
|
+
q *= @@prefix_values[num_unit]
|
594
594
|
else
|
595
|
-
q *= @@unit_values[
|
596
|
-
num << @@unit_values[
|
597
|
-
den << @@unit_values[
|
595
|
+
q *= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
|
596
|
+
num << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
|
597
|
+
den << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
|
598
598
|
end
|
599
599
|
end
|
600
|
-
@denominator.compact.each do |
|
601
|
-
if @@prefix_values[
|
602
|
-
q /= @@prefix_values[
|
600
|
+
@denominator.compact.each do |num_unit|
|
601
|
+
if @@prefix_values[num_unit]
|
602
|
+
q /= @@prefix_values[num_unit]
|
603
603
|
else
|
604
|
-
q /= @@unit_values[
|
605
|
-
den << @@unit_values[
|
606
|
-
num << @@unit_values[
|
604
|
+
q /= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
|
605
|
+
den << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
|
606
|
+
num << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
|
607
607
|
end
|
608
608
|
end
|
609
609
|
|
@@ -833,7 +833,7 @@ module RubyUnits
|
|
833
833
|
RubyUnits::Unit.new(scalar: (other.scalar + convert_to(other.temperature_scale).scalar), numerator: other.numerator, denominator: other.denominator, signature: other.signature)
|
834
834
|
end
|
835
835
|
else
|
836
|
-
@q ||= ((@@cached_units[units].scalar
|
836
|
+
@q ||= (Rational(@@cached_units[units].scalar, @@cached_units[units].base_scalar) rescue units.to_unit.to_base.scalar)
|
837
837
|
RubyUnits::Unit.new(scalar: (base_scalar + other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
838
838
|
end
|
839
839
|
else
|
@@ -870,7 +870,7 @@ module RubyUnits
|
|
870
870
|
elsif other.temperature?
|
871
871
|
raise ArgumentError, 'Cannot subtract a temperature from a differential degree unit'
|
872
872
|
else
|
873
|
-
@q ||= ((@@cached_units[units].scalar
|
873
|
+
@q ||= (Rational(@@cached_units[units].scalar, @@cached_units[units].base_scalar) rescue Rational(units.to_unit.scalar, units.to_unit.to_base.scalar))
|
874
874
|
RubyUnits::Unit.new(scalar: (base_scalar - other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
875
875
|
end
|
876
876
|
else
|
@@ -914,12 +914,16 @@ module RubyUnits
|
|
914
914
|
when Unit
|
915
915
|
raise ZeroDivisionError if other.zero?
|
916
916
|
raise ArgumentError, 'Cannot divide with temperatures' if [other, self].any?(&:temperature?)
|
917
|
-
|
917
|
+
sc = Rational(@scalar, other.scalar)
|
918
|
+
sc = sc.numerator if sc.denominator == 1
|
919
|
+
opts = RubyUnits::Unit.eliminate_terms(sc, @numerator + other.denominator, @denominator + other.numerator)
|
918
920
|
opts[:signature] = @signature - other.signature
|
919
921
|
RubyUnits::Unit.new(opts)
|
920
922
|
when Numeric
|
921
923
|
raise ZeroDivisionError if other.zero?
|
922
|
-
|
924
|
+
sc = Rational(@scalar, other)
|
925
|
+
sc = sc.numerator if sc.denominator == 1
|
926
|
+
RubyUnits::Unit.new(scalar: sc, numerator: @numerator, denominator: @denominator, signature: @signature)
|
923
927
|
else
|
924
928
|
x, y = coerce(other)
|
925
929
|
y / x
|
@@ -972,11 +976,11 @@ module RubyUnits
|
|
972
976
|
return power(other)
|
973
977
|
when Float
|
974
978
|
return self**other.to_i if other == other.to_i
|
975
|
-
valid = (1..9).map { |
|
979
|
+
valid = (1..9).map { |n| Rational(1, n) }
|
976
980
|
raise ArgumentError, 'Not a n-th root (1..9), use 1/n' unless valid.include? other.abs
|
977
|
-
return root((1
|
981
|
+
return root(Rational(1, other).to_int)
|
978
982
|
when Complex
|
979
|
-
raise ArgumentError, 'exponentiation of complex numbers is not
|
983
|
+
raise ArgumentError, 'exponentiation of complex numbers is not supported.'
|
980
984
|
else
|
981
985
|
raise ArgumentError, 'Invalid Exponent'
|
982
986
|
end
|
data/ruby-units.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: ruby-units 2.
|
5
|
+
# stub: ruby-units 2.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "ruby-units".freeze
|
9
|
-
s.version = "2.
|
9
|
+
s.version = "2.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Kevin Olbrich, Ph.D.".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2017-08-07"
|
15
15
|
s.description = "Provides classes and methods to perform unit math and conversions".freeze
|
16
16
|
s.email = ["kevin.olbrich+ruby_units@gmail.com".freeze]
|
17
17
|
s.extra_rdoc_files = [
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
]
|
46
46
|
s.homepage = "https://github.com/olbrich/ruby-units".freeze
|
47
47
|
s.licenses = ["MIT".freeze]
|
48
|
-
s.rubygems_version = "2.6.
|
48
|
+
s.rubygems_version = "2.6.11".freeze
|
49
49
|
s.summary = "A class that performs unit conversions and unit math".freeze
|
50
50
|
|
51
51
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-units
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Olbrich, Ph.D.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.6.
|
149
|
+
rubygems_version: 2.6.11
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: A class that performs unit conversions and unit math
|