plusminus 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -33,6 +33,37 @@ class Float
33
33
  end
34
34
 
35
35
 
36
+ module Plusminus
37
+
38
+ FORMATTING_METHODS = %w(
39
+ sep
40
+ mode
41
+ prec
42
+ grouping
43
+ show_all_digits
44
+ approx_mode
45
+ insignificant_digits
46
+ sci_digits
47
+ show_plus
48
+ show_exp_plus
49
+ rep
50
+ width
51
+ pad0s
52
+ base
53
+ percent
54
+ )
55
+
56
+ # define formatting methods
57
+ FORMATTING_METHODS.each do |m|
58
+ instance_eval <<-EOT
59
+ def #{m}! *args
60
+ Plusminus::PlusminusFloat::DEFAULT_FMT.#{m}! *args
61
+ self
62
+ end
63
+ EOT
64
+ end
65
+ end
66
+
36
67
 
37
68
  require File.expand_path File.dirname(__FILE__) + "/plusminus/plusminus_float.rb"
38
69
 
@@ -92,7 +92,6 @@ class Plusminus::PlusminusFloat < Numeric
92
92
  def fmt
93
93
  unless defined? @fmt
94
94
  @fmt = DEFAULT_FMT.dup
95
- digits = sig_digits
96
95
  case @value
97
96
  when -0.01 ... 0.01 then
98
97
  @fmt.mode!(:sci, sig_digits)
@@ -104,6 +103,15 @@ class Plusminus::PlusminusFloat < Numeric
104
103
  @fmt
105
104
  end
106
105
 
106
+ Plusminus::FORMATTING_METHODS.each do |m|
107
+ class_eval <<-EOT
108
+ def #{m}! *args
109
+ fmt.#{m}! *args
110
+ self
111
+ end
112
+ EOT
113
+ end
114
+
107
115
  # returns the number of significant digits
108
116
  def sig_digits
109
117
  return 0 if @value == 0
@@ -131,12 +139,18 @@ class Plusminus::PlusminusFloat < Numeric
131
139
  percent = s =~ /%\z/
132
140
  s.sub!(/%\z/, "")
133
141
  mantissa, exponent = s.split(/e/i)
142
+
143
+ # if exponential form
134
144
  if exponent
145
+ # strip decimal point or comma from end
146
+ mantissa.sub!(/[^0-9a-zA-Z]+\z/, "")
147
+
135
148
  exponent.sub!(/\A-0*/, "-").sub!(/\A0*/, "")
136
149
  res = "\\ensuremath{#{mantissa}\\cdot 10^{#{exponent}}}"
137
150
  else
138
151
  res = mantissa
139
152
  end
153
+
140
154
  res << "\\%" if percent
141
155
  res.respond_to?(:latex!) ? res.latex! : res
142
156
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "plusminus"
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bern\u{e1}t Kall\u{f3}"]
12
- s.date = "2012-04-01"
12
+ s.date = "2012-04-10"
13
13
  s.description = "A library that provides uncertainty and error propagation calculations for floats. It displays the appropriate number of digits when a number is outputted, can convert to latex using different formats."
14
14
  s.email = "kallo.bernat@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plusminus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-01 00:00:00.000000000Z
12
+ date: 2012-04-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nio
16
- requirement: &78062640 !ruby/object:Gem::Requirement
16
+ requirement: &82510800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78062640
24
+ version_requirements: *82510800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &78062300 !ruby/object:Gem::Requirement
27
+ requirement: &82510430 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *78062300
35
+ version_requirements: *82510430
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &78061930 !ruby/object:Gem::Requirement
38
+ requirement: &82510090 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *78061930
46
+ version_requirements: *82510090
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &78061600 !ruby/object:Gem::Requirement
49
+ requirement: &82509770 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *78061600
57
+ version_requirements: *82509770
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &78061250 !ruby/object:Gem::Requirement
60
+ requirement: &82509430 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78061250
68
+ version_requirements: *82509430
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &78060940 !ruby/object:Gem::Requirement
71
+ requirement: &82509090 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78060940
79
+ version_requirements: *82509090
80
80
  description: A library that provides uncertainty and error propagation calculations
81
81
  for floats. It displays the appropriate number of digits when a number is outputted,
82
82
  can convert to latex using different formats.
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: -945640049
119
+ hash: 183058865
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements: