quanty 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/parse.y CHANGED
@@ -12,7 +12,7 @@ class Parse
12
12
  prechigh
13
13
  nonassoc UMINUS
14
14
  right POW UPOW
15
- left '*' '/' '|'
15
+ left '.' '*' '/' '|'
16
16
  left '+' '-'
17
17
  preclow
18
18
 
@@ -42,6 +42,7 @@ rule
42
42
 
43
43
  seq : exp
44
44
  | seq exp { result.mul!(val[1]) }
45
+ | seq '.' exp { result.mul!(val[2]) }
45
46
  | seq '*' exp { result.mul!(val[2]) }
46
47
  | seq '/' exp { result.div!(val[2]) }
47
48
  | seq '*' num { result.fac!(val[2]) }
@@ -76,18 +77,16 @@ class Quanty
76
77
  while str.size > 0 do
77
78
  #p str
78
79
  case str
79
- when /\A[\s\n]+/ou
80
- when /\A\d+\.?\d*([eE][+-]?\d+)?/ou
80
+ when /\A[\s\n]+/o
81
+ when /\A\d+\.?\d*([eE][+-]?\d+)?/o
81
82
  @q.push [:NUMBER, $&.to_f]
82
- when /\A([A-Z]\.){2}/u
83
- when /\A[A-Za-z_]+ -/u
84
- when /\A[A-Za-z_µ]+([A-Za-z_µ0-9-]+[A-Za-z_µ])?/ou
83
+ when /\A[A-Za-z_]+([A-Za-z_0-9-]+[A-Za-z_])?/o
85
84
  @q.push [:WORD, $&]
86
- when /\A[$%'"]'?/ou
85
+ when /\A[$%'"]'?/o
87
86
  @q.push [:WORD, $&]
88
- when /\A\^|\A\*\*/ou
87
+ when /\A\^|\A\*\*/o
89
88
  @q.push [:POW, $&]
90
- when /\A./ou
89
+ when /\A./o
91
90
  @q.push [$&,$&]
92
91
  end
93
92
  str = $'
@@ -21,87 +21,93 @@ Featuring:
21
21
  == Quanty class
22
22
 
23
23
  === Super Class:
24
- Object (Numeric is better??)
24
+ Object (Numeric is better??)
25
25
 
26
26
  === Class method:
27
27
  --- Quanty.new([value],[unit])
28
28
  --- Quanty([value],[unit])
29
- Create Quanty class instance having ((|value|)) and ((|unit|)) (is String).
30
- If ((|value|)) is omitted, ((|value|)) = 1 is assumed.
31
- If ((|unit|)) is omitted, ((|unit|)) = "" is assumed,
32
- which is regarded as a quantity with "dimensionless" unit
33
- (i.e. all dimensions of unit are zero).
34
- Refer to ((<Notation of unit>)) below.
29
+ Create Quanty class instance having ((|value|)) and ((|unit|)) (is String).
30
+ If ((|value|)) is omitted, ((|value|)) = 1 is assumed.
31
+ If ((|unit|)) is omitted, ((|unit|)) = "" is assumed,
32
+ which is regarded as a quantity with "dimensionless" unit
33
+ (i.e. all dimensions of unit are zero).
34
+ Refer to ((<Notation of unit>)) below.
35
35
 
36
36
  === Methods:
37
37
  --- self + other
38
38
  --- self - other
39
- Addition and subtraction of quantities.
40
- Operation is made after
41
- the unit of ((|other|)) is converted to the unit of ((|self|)).
42
- Exception is raised if unit conversion is failed.
43
- Return the Quanty class instance with the unit of ((|self|)).
39
+ Addition and subtraction of quantities.
40
+ Operation is made after
41
+ the unit of ((|other|)) is converted to the unit of ((|self|)).
42
+ Exception is raised if unit conversion is failed.
43
+ Return the Quanty class instance with the unit of ((|self|)).
44
44
 
45
45
  --- self * other
46
- Multiplication of quantities.
47
- Resulting unit is made by concatenating ((|self|)) and ((|other|)).
46
+ Multiplication of quantities.
47
+ Resulting unit is made by concatenating ((|self|)) and ((|other|)).
48
+
48
49
  --- self / other
49
- Division of quantities.
50
- Resulting unit is made by placing (({"/"}))
51
- between ((|self|)) and ((|other|)), and concatenating them.
50
+ Division of quantities.
51
+ Resulting unit is made by placing (({"/"}))
52
+ between ((|self|)) and ((|other|)), and concatenating them.
52
53
 
53
54
  --- self ** number
54
- Power of quantities.
55
- Resulting unit is made by "(unit of self)^((|number|))"
55
+ Power of quantities.
56
+ Resulting unit is made by "(unit of self)^((|number|))"
56
57
 
57
58
  --- self == other
58
59
  --- self < other
59
60
  --- self <= other
60
61
  --- self > other
61
62
  --- self >= other
62
- Comparison of quantities.
63
+ Comparison of quantities.
63
64
 
64
65
  --- coerce(number)
65
- Convert ((|number|)) to Quanty class instance with dimensionless unit,
66
- then return [((|number|)), ((|self|))].
66
+ Convert ((|number|)) to Quanty class instance with dimensionless unit,
67
+ then return [((|number|)), ((|self|))].
68
+
69
+ --- to_si
70
+ --- to_SI
71
+ Convert ((|self|)) to the SI unit system.
67
72
 
68
73
  --- to_f
69
- If ((|self|)) is a quantity with a dimensionless unit, return its value.
70
- If ((|self|)) is a quantity with an angular unit,
71
- return the value converted into radian.
72
- Otherwise, raise exception.
74
+ If ((|self|)) is a quantity with a dimensionless unit, return its value.
75
+ If ((|self|)) is a quantity with an angular unit,
76
+ return the value converted into radian.
77
+ Otherwise, raise exception.
73
78
 
74
79
  --- unit
75
- Return the string of unit.
80
+ Return the string of unit.
76
81
 
77
82
  --- val
78
83
  --- value
79
- Return the value.
84
+ Return the value.
80
85
 
81
86
  --- want(unit)
82
- Convert ((|self|)) to a quantity with ((|unit|)) (is String),
83
- and return Quanty class instance.
87
+ Convert ((|self|)) to a quantity with ((|unit|)) (is String),
88
+ and return Quanty class instance.
84
89
 
85
90
  == Notation of unit
86
91
 
87
- * Multiplication
88
- 'N m' , 'N*m' are same.
92
+ ==== Multiplication
93
+ 'N m' == 'N*m'
89
94
 
90
- * Division
91
- '/s' , 'm/s'
95
+ ==== Division
96
+ '/s' , 'm/s'
92
97
 
93
- * Power
94
- 'm-2' , 'm^-2' , 'm**-2' are all same.
98
+ ==== Power
99
+ 'm-2' == 'm^-2' == 'm**-2'
95
100
 
96
- * Numerical factor
97
- '12 inch' --- same as 'feet'.
101
+ ==== Numerical factor
102
+ '12 inch' == 'feet'
98
103
 
99
- * Combination
100
- 'm/s*m' --- same as 'm^2/s'.
101
- 'm/(s*m)' --- same as '/s'.
104
+ ==== Combination rule
105
+ 'm/s*m' == 'm^2/s'.
106
+ 'm/(s*m)' == '/s'.
102
107
 
103
- * See ((%parse.y%)) for more.
108
+ + See ((%parse.y%)) for more.
104
109
 
105
- by ((<Masahiro Tanaka|URL:http://www.ir.isas.ac.jp/~masa/index-e.html>))
110
+ == Author
111
+ ((<Masahiro Tanaka|URL:http://www.ir.isas.ac.jp/~masa/index-e.html>))
106
112
  (2001-04-25)
107
113
  =end
@@ -24,79 +24,85 @@
24
24
  === ���饹�᥽�å�:
25
25
  --- Quanty.new([value],[unit])
26
26
  --- Quanty([value],[unit])
27
- �̤��ͤ�((|value|))��ñ�̤�((|unit|)) (ʸ����)�Ȥ���
28
- Unit ���饹�Υ��󥹥��󥹤��������롣
29
- ((|value|))����ά���줿���ϡ�1�����ꤵ�줿����Ʊ����
30
- ((|unit|))����ά���줿���ϡ�""�����ꤵ�줿����Ʊ���ǡ�ñ�̤ʤ��̤ˤʤ롣
31
- ñ�̤ν����ϡ�����((<ñ��ɽ��ˡ>))�򻲾ȡ�
27
+ �̤��ͤ�((|value|))��ñ�̤�((|unit|)) (ʸ����)�Ȥ���
28
+ Unit ���饹�Υ��󥹥��󥹤��������롣
29
+ ((|value|))����ά���줿���ϡ�1�����ꤵ�줿����Ʊ����
30
+ ((|unit|))����ά���줿���ϡ�""�����ꤵ�줿����Ʊ���ǡ�ñ�̤ʤ��̤ˤʤ롣
31
+ ñ�̤ν����ϡ�����((<ñ��ɽ��ˡ>))�򻲾ȡ�
32
32
 
33
33
  === �᥽�å�:
34
34
  --- self + other
35
35
  --- self - other
36
- �̤βû���������
37
- ((|other|))��ñ�̤�((|self|))��ñ�̤��Ѵ����Ʊ黻���롣
38
- ñ���Ѵ����Ǥ��ʤ�����㳰��ȯ�����롣
39
- ��̤�((|self|))��ñ�̤ˤ��� Quanty ���饹�Υ��󥹥��󥹤��֤���
36
+ �̤βû���������
37
+ ((|other|))��ñ�̤�((|self|))��ñ�̤��Ѵ����Ʊ黻���롣
38
+ ñ���Ѵ����Ǥ��ʤ�����㳰��ȯ�����롣
39
+ ��̤�((|self|))��ñ�̤ˤ��� Quanty ���饹�Υ��󥹥��󥹤��֤���
40
40
 
41
41
  --- self * other
42
- �̤ξ軻��
43
- ��̤�ñ�̤ϡ�((|self|))��((|other|))��ñ�̤�Ϣ�뤷�ƺ�롣
42
+ �̤ξ軻��
43
+ ��̤�ñ�̤ϡ�((|self|))��((|other|))��ñ�̤�Ϣ�뤷�ƺ�롣
44
+
44
45
  --- self / other
45
- �̤ν�����
46
- ��̤�ñ�̤ϡ�
47
- ((|self|))��((|other|))��ñ�̤�(({"/"}))��Ϥ����Ϣ�뤷�ƺ�롣
46
+ �̤ν�����
47
+ ��̤�ñ�̤ϡ�
48
+ ((|self|))��((|other|))��ñ�̤�(({"/"}))��Ϥ����Ϣ�뤷�ƺ�롣
48
49
 
49
50
  --- self ** number
50
- �̤��Ѿ衣
51
- ��̤�ñ�̤ϡ�"(((|self|))��ñ��)^((|number|))" �Ȥ��ƺ�롣
51
+ �̤��Ѿ衣
52
+ ��̤�ñ�̤ϡ�"(((|self|))��ñ��)^((|number|))" �Ȥ��ƺ�롣
52
53
 
53
54
  --- self == other
54
55
  --- self < other
55
56
  --- self <= other
56
57
  --- self > other
57
58
  --- self >= other
58
- �̤���ӡ�
59
+ �̤���ӡ�
59
60
 
60
61
  --- coerce(number)
61
- ((|number|))��ñ�̤ʤ�Quanty���饹�Υ��󥹥��󥹤ˤ���
62
- [((|number|)),((|self|))]�Ȥ����֤���
62
+ ((|number|))��ñ�̤ʤ�Quanty���饹�Υ��󥹥��󥹤ˤ���
63
+ [((|number|)),((|self|))]�Ȥ����֤���
64
+
65
+ --- to_si
66
+ --- to_SI
67
+ ((|self|))��SIñ�̷Ϥ��Ѵ����롣
63
68
 
64
69
  --- to_f
65
- ((|self|))��ñ�̤ʤ��̤ξ��ϡ����Ȥ��ͤ��֤���
66
- ((|self|))�����٤ξ��ϡ�radian���Ѵ������ͤ��֤���
67
- ����ʳ���ñ�̤ξ��ϡ��㳰��ȯ�����롣
70
+ ((|self|))��ñ�̤ʤ��̤ξ��ϡ����Ȥ��ͤ��֤���
71
+ ((|self|))�����٤ξ��ϡ�radian���Ѵ������ͤ��֤���
72
+ ����ʳ���ñ�̤ξ��ϡ��㳰��ȯ�����롣
68
73
 
69
74
  --- unit
70
- ñ�̤�ʸ������֤���
75
+ ñ�̤�ʸ������֤���
71
76
 
72
77
  --- val
73
78
  --- value
74
- �̤��ͤ��֤���
79
+ �̤��ͤ��֤���
75
80
 
76
81
  --- want(unit)
77
- ((|self|))�� ((|unit|)) (ʸ����) ��ñ�̤Ȥ����̤��Ѵ����롣
82
+ ((|self|))�� ((|unit|)) (ʸ����) ��ñ�̤Ȥ����̤��Ѵ����롣
78
83
 
79
84
 
80
85
  == ñ��ɽ��ˡ
81
86
 
82
- * ��ˡ
83
- 'N m' �� 'N*m' ��Ʊ����
87
+ ==== ��ˡ
88
+ 'N m' == 'N*m'
84
89
 
85
- * ��ˡ
86
- '/s' , 'm/s'
90
+ ==== ��ˡ
91
+ '/s' , 'm/s'
87
92
 
88
- * �٤�
89
- 'm-2' , 'm^-2' , 'm**-2' �Ϥ��٤�Ʊ����
93
+ ==== �٤�
94
+ 'm-2' == 'm^-2' == 'm**-2'
90
95
 
91
- * ������
92
- '12 inch' --- 'feet' ��Ʊ����
96
+ ==== ������
97
+ '12 inch' == 'feet'
93
98
 
94
- * ����
95
- 'm/s*m' --- 'm^2/s' ��Ʊ����
96
- 'm/(s*m)' --- '/s' ��Ʊ����
99
+ ==== ����
100
+ 'm/s*m' == 'm^2/s'.
101
+ 'm/(s*m)' == '/s'.
97
102
 
98
- * �ܺ٤� ((%parse.y%)) �򻲾ȤΤ��ȡ�
103
+ + �ܺ٤� ((%parse.y%)) �򻲾ȤΤ��ȡ�
99
104
 
100
- by ((<Masahiro Tanaka|URL:http://www.ir.isas.ac.jp/~masa/>))
105
+ == Author
106
+ ((<Masahiro Tanaka|URL:http://www.ir.isas.ac.jp/~masa/index-e.html>))
101
107
  (2001-04-25)
102
108
  =end
data/units.dat CHANGED
@@ -87,15 +87,15 @@
87
87
  kg ! # Mass of the international prototype
88
88
  kilogram kg
89
89
 
90
- s ! # Duration of 9192631770 periods of the radiation
91
- second s # corresponding to the transition between the two hyperfine
92
- # levels of the ground state of the cesium-133 atom
93
-
94
90
  m ! # Length of the path traveled by light in a vacuum
95
91
  meter m # during 1|299792458 seconds. Originally meant to be
96
92
  # 1e-7 of the length along a meridian from the equator
97
93
  # to a pole.
98
94
 
95
+ s ! # Duration of 9192631770 periods of the radiation
96
+ second s # corresponding to the transition between the two hyperfine
97
+ # levels of the ground state of the cesium-133 atom
98
+
99
99
  A ! # The current which produces a force of 2e-7 N/m between two
100
100
  ampere A # infinitely long wires that are 1 meter apart
101
101
  amp ampere
@@ -145,6 +145,9 @@ bit ! # Basic unit of information (entropy). The entropy in bits
145
145
  # p(i) is the probability that the random variable takes
146
146
  # on the value i.
147
147
 
148
+ mag ! # Magnitude used in Astronomy
149
+ magnitude mag # added by M.Tanaka
150
+
148
151
  pi 3.14159265358979323846
149
152
 
150
153
  ###########################################################################
@@ -262,7 +265,7 @@ septendecillion 1e54
262
265
  octodecillion 1e57
263
266
  novemdecillion 1e60
264
267
  vigintillion 1e63
265
- centillion 1e303
268
+ #centillion 1e303
266
269
 
267
270
  googol 1e100
268
271
 
@@ -3404,21 +3407,21 @@ blanc 1|24 periot
3404
3407
  # Some definitions using ISO 8859-1 characters
3405
3408
  #
3406
3409
 
3407
- ¼- 1|4
3408
- ½- 1|2
3409
- ¾- 3|4
3410
- µ- micro
3411
- ¢ cent
3412
- £ britainpound
3413
- ¥ japanyen
3414
- ångström angstrom
3415
- Å angstrom
3416
- röntgen roentgen
3417
- °C degC
3418
- °F degF
3419
- °K K # °K is incorrect notation
3420
- °R degR
3421
- ° degree
3410
+ �- 1|4
3411
+ �- 1|2
3412
+ �- 3|4
3413
+ �- micro
3414
+ cent
3415
+ britainpound
3416
+ japanyen
3417
+ �ngstr�m angstrom
3418
+ angstrom
3419
+ r�ntgen roentgen
3420
+ C degC
3421
+ F degF
3422
+ K K # K is incorrect notation
3423
+ R degR
3424
+ degree
3422
3425
 
3423
3426
 
3424
3427
  ############################################################################
@@ -3465,7 +3468,7 @@ slugf slug force
3465
3468
  slinch lbf s^2 / inch # Mass unit derived from inch second
3466
3469
  slinchf slinch force # pound-force system. Used in space
3467
3470
  geepound slug
3468
- olddidotpoint 1|72 frenchinch # François Ambroise Didot, one of
3471
+ olddidotpoint 1|72 frenchinch # Fran�ois Ambroise Didot, one of
3469
3472
  frenchprinterspoint olddidotpoint
3470
3473
  denier 1|9 tex # used for silk and rayon
3471
3474
  austriaschilling 1|13.7603 euro
@@ -3520,30 +3523,3 @@ perm_twentythree perm_23C
3520
3523
  # marathon 26 miles + 385 yards
3521
3524
  # eggvolume 3 tablespoons + 1|2 tsp
3522
3525
  # standardgauge 4 ft + 8.5 in # Standard width between railroad track
3523
-
3524
-
3525
- ###########################################################################
3526
- # #
3527
- # oddb units #
3528
- # #
3529
- ###########################################################################
3530
-
3531
- UPhEur ! # Unite Pharmacopee Europeenne
3532
- U.Ph.Eur. UPhEur
3533
-
3534
- UI !
3535
- U UI
3536
- U. UI
3537
- U.I. UI
3538
- IE UI
3539
- I.E. IE
3540
-
3541
- LSU ! # lipoprotein lipase releasing units
3542
-
3543
- tablet ! # one of the "official doses" in ATC-DDD
3544
-
3545
- Mio- 1e6
3546
- Mio 1e6
3547
- µ- 1e-6
3548
- u- 1e-6
3549
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quanty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Masahiro Tanaka, Masaomi Hatakeyama, Zeno R.R. Davatz
@@ -59,6 +59,7 @@ files:
59
59
  - Rakefile
60
60
  - extconf.rb
61
61
  - lib/quanty.rb
62
+ - lib/quanty/.cvsignore
62
63
  - lib/quanty/fact.rb
63
64
  - lib/quanty/main.rb
64
65
  - lib/quanty/parse.rb