Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/m500.rb

Instance Method Summary collapse

Instance Method Details

#append_K(a) ⇒ Object



237
238
239
240
# File 'lib/m500.rb', line 237

def append_K(a)
  a = a.to_Frac
  self.gsub!("&&&&","Fraction(Zahlen(#{a.integer.to_s}),Quotient(Zahlen(#{a.properfraction.numerator.to_s}),Zahlen(#{a.properfraction.denominator.to_s})))")
end

#is_Dec?Boolean



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/m500.rb', line 103

def is_Dec?
  t = true
  re = /(^-?[0-9]+)\\#{Decimal::decimalSeparator}([0-9]+)/
  re = /(^-?[0-9]+)\.([0-9]+)/
  md = re.match(self.to_s)
  if md.nil?
    t = false
  else
    t = false  if md[1].nil? && md[2].nil? && md[3].nil?
  end
  t
end

#is_f?Boolean



56
57
58
59
60
61
62
# File 'lib/m500.rb', line 56

def is_f?
  t = true
  re = /(\-*\d+).(\d+)e([-|+])(\d+)/
  md =  re.match(self)
  t = false  if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
  t
end

#is_Frac?Boolean



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/m500.rb', line 92

def is_Frac?
  t = true
  re = /(^-?[0-9]+) ([0-9]+)\/([0-9]+)/
  md =  re.match(self)
  if md.nil?
    t = false
  else
    t = false  if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
  end
  t
end

#is_K?Boolean



223
224
225
226
227
228
229
# File 'lib/m500.rb', line 223

def is_K?
  t = true
  re = /(\d+)#{Kettenbruch::Separator}(\d+)/
  md =  re.match(self)
  t = false  if md[1].nil? && md[2].nil?
  t
end

#is_K_Leicht?Boolean



230
231
232
233
234
235
236
# File 'lib/m500.rb', line 230

def is_K_Leicht?
  t = true
  re = /(\d+)#{Kettenbruch::Separator}(\d+)/
  md =  re.match(self)
  t = false  if md[1].nil? && md[2].nil?
  t
end

#is_N0?Boolean



69
70
71
72
73
74
# File 'lib/m500.rb', line 69

def is_N0?
  re = /(^[0-9]+)$/
  md = re.match(self.to_s)
  t = emptySet
  t = md[1].to_i.to_N unless md.nil?
end

#is_N?Boolean



63
64
65
66
67
68
# File 'lib/m500.rb', line 63

def is_N?
  re = /(^[0-9]+)$/
  md = re.match(self.to_s)
  t = emptySet
  t = md[1].to_i.to_N unless md.nil?
end

#is_Q?Boolean



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/m500.rb', line 42

def is_Q?
  t = true
  re = /(\d+)\/(\d+)/
  md =  re.match(self)
  if md.nil? then
    t = is_Z?
  else
    t = false  if md[1].nil? && md[2].nil? && md[3].nil? && md[4].nil?
  end
  t
end

#is_R?Boolean



117
118
119
# File 'lib/m500.rb', line 117

def is_R?
  false
end

#is_r?Boolean



53
54
55
# File 'lib/m500.rb', line 53

def is_r?
  Rational(self).kind_of?(Rational)
end

#is_Sig?Boolean



115
116
# File 'lib/m500.rb', line 115

def is_Sig?
end

#is_Z?Boolean



75
76
77
78
79
80
# File 'lib/m500.rb', line 75

def is_Z?
  re = /(^-?[0-9]+)$/
  md = re.match(self.to_s)
  t = emptySet
  t = Zahlen(md[1].to_i) unless md.nil?
end

#to_DecObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/m500.rb', line 150

def to_Dec
  re = /^-/
  md = re.match(self.to_s)
  e = -1    
  e = 1 if  md.to_a.empty?
  md = nil
  t0 = 0
  t1 = '0'
  t2 = nil
  t3 = nil
  re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)\[([0-9]+)\]/
  re = /([0-9]+)\.([0-9]+)\[([0-9]+)\]/
  md = re.match(self.to_s)
  if md.to_a.empty? then
    re = /([0-9]+)#{Decimal::decimalSeparator}([0-9]+)/
    re = /([0-9]+)\.([0-9]+)/
    md = re.match(self.to_s)
    if md.to_a.empty? then
      re = /([0-9]+)#{Decimal::decimalSeparator}\[([0-9]+)\]/
      re = /([0-9]+)\.\[([0-9]+)\]/
      md = re.match(self.to_s)
      if md.to_a.empty? then
        re = /([0-9]+)/
        md = re.match(self.to_s)
        t0 = 0
        t1 = '0'
        t2 = nil
        t3 = md[1].to_i
      else
        t0 = 0
        t1 = md[2] #.to_i
        t2 = nil
        t3 = md[1].to_i
      end
    else
      t0 = md[2].scan(/^0+/)[0].length unless  md[2].scan(/^0+/).empty?
      t1 = md[3] unless md[3].nil?
      t2 = md[2].to_i
      t3 = md[1].to_i
    end
  else
    t0 = md[2].scan(/^0+/)[0].length unless  md[2].scan(/^0+/).empty?
    t1 = md[3] unless md[3].nil?
    t2 = md[2].to_i
    t3 = md[1].to_i
  end
  Decimal(t3,t2,t1,t0,e)
end

#to_FracObject



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/m500.rb', line 198

def to_Frac
  re = /(^[0-9]+) ([0-9]+)\/([0-9]+)/
  md = re.match(self.to_s)
  t = nil
  if not  md.nil? then
    t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i)) 
  else
    re = /^-1\(([0-9]+) ([0-9]+)\/([0-9]+)\)/
    md = re.match(self.to_s)
    if not  md.nil? then
      t = Fraction(Zahlen(md[1].to_i),Quotient(md[2].to_i, md[3].to_i),-1) unless md.nil?
    else
      re = /(\-*[0-9]+)\/([0-9]+)/
      md = re.match(self.to_s)
      if not  md.nil? then
        t = Fraction(Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i)))
      else
        t=Fraction(Quotient(self.to_i,1))
      end
    end
  end    
end

#to_KObject



241
242
243
244
245
246
247
248
# File 'lib/m500.rb', line 241

def to_K
  a = self.split(";")
  int = a.at(0).to_i
  re = /'...'/
  md =  re.match(a.at(1))
  frK = eval("[" + a.at(1).gsub("...","") + "]" )
  ([int] + frK).to_K
end

#to_NObject



120
121
122
123
124
125
# File 'lib/m500.rb', line 120

def to_N
  re = /(^[0-9]+)/
  md = re.match(self.to_s)
  t = emptySet
  t = md[1].to_i.to_N unless md.nil?
end

#to_N0Object



126
127
128
129
130
131
# File 'lib/m500.rb', line 126

def to_N0
  re = /(^[0-9]+)/
  md = re.match(self.to_s)
  t = emptySet
  t = md[1].to_i.to_N0 unless md.nil?
end

#to_QObject



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/m500.rb', line 138

def to_Q
  re = /(-?[0-9]+)\/([0-9]+)/
  md = re.match(self.to_s)
  ret = emptySet
  if md then
    t = 1
    Natural(md[2].to_i).kind_of?(EmptySetClass) ? ret = infinity : ret = Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i))
  else 
    Natural(md[2].to_i).kind_of?(EmptySetClass) ? ret = infinity : ret = Quotient(Zahlen(md[1].to_i),Natural(md[2].to_i))
  end
  ret
end

#to_SigObject



249
250
# File 'lib/m500.rb', line 249

def to_Sig
end

#to_STObject



220
221
222
# File 'lib/m500.rb', line 220

def to_ST
  ST.new(self)
end

#to_ZObject



132
133
134
135
136
137
# File 'lib/m500.rb', line 132

def to_Z
  re = /(^-?[0-9]+)/
  md = re.match(self.to_s)
  t = emptySet
  t = Zahlen(md[1].to_i) unless md.nil?
end