primitive_wrapper 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6aa5f4b217c6e6eddf82f17d5b062a125acbec26
4
- data.tar.gz: e0ac33dd51b163d938c3821c0908690548529902
3
+ metadata.gz: 9ac0598322b63f9401a9cd13d709637c90e98bd8
4
+ data.tar.gz: e2347dc45a00f18d27a3b09c3cd42de73f773e86
5
5
  SHA512:
6
- metadata.gz: 047242da1920d239a5ee10d942d2246647f625f87985bd2faf78eddc34897224550f14ce020a8828e1a06f8a2f03dcf0cd09757438ab305aeeba7541b7cf1483
7
- data.tar.gz: e824f363837b937dc44311930562a32ab05dbc8c128f7aefdfe7491f4264bc3b09f2a317ae610533fdb8bca1c20c019844c3ec20ad6c6cc739eac9ccf5193b90
6
+ metadata.gz: 9fe51325ebbc3c2e0f672d7b9eb11ff7af0fe6a556332d3cd9e4db3cfb2bdcf55265c29a8c9ba37a5785df349204572409c65f4ac5d0d687d03dfae9b9ba85f4
7
+ data.tar.gz: ae8f06e0613ae56258172296f18f6f8d4782b8abd62797f9cb1a559d57d04f0fb015f017d62fe13a2786ad57ae1640475d652a2ec709ec73acaabe8249e1c269
data/README.md CHANGED
@@ -328,6 +328,10 @@ frac = Math::PI.to_fraction(0.0001) # (Fraction==>(355/113))
328
328
  frac = Math::PI.to_fraction # (Fraction==>(884279719003555/281474976710656))
329
329
  # note: Rational does not have approximate construction
330
330
 
331
+ # Construction: using float with target denominator
332
+ frac = Fraction(Math::PI, 113) # (Fraction==>(355/113))
333
+ frac = Fraction(Math::PI, 7) # (Fraction==>(22/7))
334
+
331
335
  # mutating methods:
332
336
  frac = Math::PI.to_fraction(0.0001)
333
337
  frac.negate! # make negative
@@ -613,6 +617,10 @@ So it is left to you to decide.
613
617
 
614
618
  ## Revision History
615
619
 
620
+ ### Version 2.1.0
621
+ * Bug fixes for Fraction wrapper
622
+ * New construction method for Fraction
623
+
616
624
  ### Version 2.1.0
617
625
  * Added Fraction wrapper for Rational types
618
626
 
@@ -747,7 +747,9 @@ class Fraction < ValueAdd
747
747
  top += 1
748
748
  end
749
749
  end
750
- return Fraction.new(top.prim_value,bot.prim_value)
750
+ frac = Fraction.new(top.prim_value,bot.prim_value)
751
+ frac = -frac if neg
752
+ return frac
751
753
  end
752
754
 
753
755
  def initialize(*prms)
@@ -758,8 +760,18 @@ class Fraction < ValueAdd
758
760
  @value = Rational(prms[0].prim_value)
759
761
  elsif 2==prms.count
760
762
  if prms[0].type_of? Float
761
- fract = self.class.approximate_by_float(prms[0].prim_value,prms[1].prim_value)
762
- @value = fract.prim_value
763
+ if prms[1].type_of? Integer
764
+ sign = prms[0].negative? ? -1:1
765
+ num = prms[0].abs
766
+ whole = num.floor
767
+ frac = num-whole
768
+ num = (frac * prms[1]).round
769
+ frac = Fraction.new(whole, num, prms[1]) * sign
770
+ @value = frac.prim_value
771
+ else
772
+ fract = self.class.approximate_by_float(prms[0].prim_value,prms[1].prim_value)
773
+ @value = fract.prim_value
774
+ end
763
775
  else
764
776
  @value = Rational(prms[0].prim_value,prms[1].prim_value)
765
777
  end
@@ -5,5 +5,5 @@
5
5
  # adding rational to fraction
6
6
 
7
7
  module PrimitiveWrapper
8
- VERSION = "2.1.0"
8
+ VERSION = "2.2.0"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primitive_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-03 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blockify