trusted-number 0.3.0 → 0.3.1
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 +6 -4
- data/examples/add.rb +14 -11
- data/examples/compare.rb +12 -13
- data/examples/factory.rb +33 -0
- data/examples/line.rb +8 -2
- data/examples/new.rb +8 -11
- data/examples/use.rb +2 -0
- data/lib/trusted-number/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f6d0c496a6d24a88d195ea7cda386e9f7a65bdbf6a797cefcc8650ad295339e
|
|
4
|
+
data.tar.gz: 4195af37b6cb7904851c863d1a9dbc897fa23398b005e551388848fb7190889c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 883c52b8d968d257c1805949f7bd33b403f539e24e7d24a12f8683164d1b6569acc15b478d03aca48b0cd4f01c90b2504248e41bb6242683aa27315b2ebb8af3
|
|
7
|
+
data.tar.gz: a32750a14a9115af51d6476cf63055047871a24eb94153b734c8ae5b4e6052f6dadb03d8b69ee4c0b166297fef082a75ae2039e668d5308f4ad66506d17096b6
|
data/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# trusted-number
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/trusted-number)
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
A trusted number is a number whose value will not change secretly.
|
|
4
8
|
|
|
5
9
|
For example (with base 10 numbers): `0.1 + 0.2 == 0.3`.
|
|
@@ -20,8 +24,7 @@ require "trusted-number"
|
|
|
20
24
|
dec1 = TrustedNumber.new("0.1")
|
|
21
25
|
dec2 = TrustedNumber.new("0.2")
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
puts dec1 + dec2 #=> 0.3
|
|
27
|
+
dec1 + dec2 #=> 0.3
|
|
25
28
|
```
|
|
26
29
|
|
|
27
30
|
Example (base 2):
|
|
@@ -30,8 +33,7 @@ Example (base 2):
|
|
|
30
33
|
bin1 = TrustedNumber.new("101.1", base: 2)
|
|
31
34
|
bin2 = TrustedNumber.new("0.1", base: 2)
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
puts bin1 + bin2 #=> 110(b2)
|
|
36
|
+
bin1 + bin2 #=> 110(b2)
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
> More [examples](./examples/)
|
data/examples/add.rb
CHANGED
|
@@ -3,20 +3,23 @@ require_relative "../lib/trusted-number"
|
|
|
3
3
|
require_relative "line"
|
|
4
4
|
|
|
5
5
|
line
|
|
6
|
-
|
|
6
|
+
num1 = TrustedNumber.new("101.1", base: 2)
|
|
7
|
+
num2 = TrustedNumber.new("0.1", base: 2)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
puts "Result : #{res.value}"
|
|
9
|
+
puts "Example: #{num1.value} + #{num2.value}"
|
|
10
|
+
puts "Base: #{num1.base}"
|
|
11
|
+
res = num1 + num2
|
|
12
|
+
puts "Result: #{res.value}"
|
|
13
13
|
puts res.about
|
|
14
14
|
|
|
15
15
|
line
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
dec2 = TrustedNumber.new("0.2")
|
|
16
|
+
num1 = TrustedNumber.new("0.1")
|
|
17
|
+
num2 = TrustedNumber.new("0.2")
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
puts "
|
|
19
|
+
puts "Example: #{num1.value} + #{num2.value}"
|
|
20
|
+
puts "Base: #{num1.base}"
|
|
21
|
+
res = num1 + num2
|
|
22
|
+
puts "Result: #{res.value}"
|
|
22
23
|
puts res.about
|
|
24
|
+
|
|
25
|
+
line
|
data/examples/compare.rb
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require_relative "../lib/trusted-number"
|
|
3
|
-
|
|
4
|
-
def line
|
|
5
|
-
puts "\n" + "-" * 40
|
|
6
|
-
end
|
|
3
|
+
require_relative "line"
|
|
7
4
|
|
|
8
5
|
num1 = TrustedNumber.new("0")
|
|
9
6
|
num2 = TrustedNumber.new("-0.2")
|
|
@@ -12,18 +9,20 @@ num4 = TrustedNumber.new("4.5")
|
|
|
12
9
|
|
|
13
10
|
line
|
|
14
11
|
puts "Example:"
|
|
15
|
-
puts "
|
|
16
|
-
puts "
|
|
17
|
-
puts "
|
|
12
|
+
puts " #{num1.value} == #{num2.value} => #{num1 == num2}"
|
|
13
|
+
puts " #{num1.value} > #{num2.value} => #{num1 > num2}"
|
|
14
|
+
puts " #{num1.value} < #{num2.value} => #{num1 < num2}"
|
|
18
15
|
|
|
19
16
|
line
|
|
20
17
|
puts "Example:"
|
|
21
|
-
puts "
|
|
22
|
-
puts "
|
|
23
|
-
puts "
|
|
18
|
+
puts " #{num2.value} == #{num3.value} => #{num2 == num3}"
|
|
19
|
+
puts " #{num2.value} > #{num3.value} => #{num2 > num3}"
|
|
20
|
+
puts " #{num2.value} < #{num3.value} => #{num2 < num3}"
|
|
24
21
|
|
|
25
22
|
line
|
|
26
23
|
puts "Example:"
|
|
27
|
-
puts "
|
|
28
|
-
puts "
|
|
29
|
-
puts "
|
|
24
|
+
puts " #{num4.value} == #{num3.value} => #{num4 == num3}"
|
|
25
|
+
puts " #{num4.value} > #{num3.value} => #{num4 > num3}"
|
|
26
|
+
puts " #{num4.value} < #{num3.value} => #{num4 < num3}"
|
|
27
|
+
|
|
28
|
+
line
|
data/examples/factory.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative "../lib/trusted-number"
|
|
3
|
+
require_relative "line"
|
|
4
|
+
|
|
5
|
+
b2 = TrustedNumber.factory(2)
|
|
6
|
+
b10 = TrustedNumber.factory(10)
|
|
7
|
+
b16 = TrustedNumber.factory(16)
|
|
8
|
+
|
|
9
|
+
line(eol: false)
|
|
10
|
+
num1 = b10.call(0.1)
|
|
11
|
+
num2 = b10.call("0.2")
|
|
12
|
+
print "Example (base #{num1.base}): #{num1.value} + #{num2.value} == "
|
|
13
|
+
puts num1 + num2
|
|
14
|
+
|
|
15
|
+
line(eol: false)
|
|
16
|
+
num1 = b2.call("101.1")
|
|
17
|
+
num2 = b2.call(0.1)
|
|
18
|
+
print "Example (base #{num1.base}): #{num1.value} + #{num2.value} == "
|
|
19
|
+
puts num1 + num2
|
|
20
|
+
|
|
21
|
+
line(eol: false)
|
|
22
|
+
num1 = b10.call(3.1415)
|
|
23
|
+
num2 = b10.call(10)
|
|
24
|
+
print "Example (base #{num1.base}): #{num1.value} + #{num2.value} == "
|
|
25
|
+
puts num1 + num2
|
|
26
|
+
|
|
27
|
+
line(eol: false)
|
|
28
|
+
num1 = b16.call("af")
|
|
29
|
+
num2 = b16.call(2)
|
|
30
|
+
print "Example (base #{num1.base}): #{num1.value} + #{num2.value} == "
|
|
31
|
+
puts num1 + num2
|
|
32
|
+
|
|
33
|
+
line(eol: false)
|
data/examples/line.rb
CHANGED
data/examples/new.rb
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require_relative "../lib/trusted-number"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def line
|
|
6
|
-
puts "\n" + "-" * 40
|
|
7
|
-
end
|
|
3
|
+
require_relative "line"
|
|
8
4
|
|
|
9
5
|
num = TrustedNumber.new("123.456")
|
|
10
6
|
|
|
11
7
|
line
|
|
12
8
|
puts "Example: 123.456"
|
|
13
|
-
puts "
|
|
14
|
-
puts "
|
|
15
|
-
puts "
|
|
16
|
-
puts "
|
|
17
|
-
puts "
|
|
18
|
-
puts "
|
|
9
|
+
puts " base : #{num.base}"
|
|
10
|
+
puts " sign : #{num.sign}"
|
|
11
|
+
puts " predot : #{num.predot}"
|
|
12
|
+
puts " postdot : #{num.postdot}"
|
|
13
|
+
puts " value : #{num.value}"
|
|
14
|
+
puts " about : #{num.about}"
|
|
15
|
+
line
|
data/examples/use.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trusted-number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Vargas
|
|
@@ -9,7 +9,8 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description: A trusted number is a number whose value will not change secretly.
|
|
12
|
+
description: 'A trusted number is a number whose value will not change secretly. For
|
|
13
|
+
example (base 10): 0.1 + 0.2 is 0.3.'
|
|
13
14
|
email:
|
|
14
15
|
- dvarrui@proton.me
|
|
15
16
|
executables: []
|
|
@@ -26,6 +27,7 @@ files:
|
|
|
26
27
|
- docs/use.md
|
|
27
28
|
- examples/add.rb
|
|
28
29
|
- examples/compare.rb
|
|
30
|
+
- examples/factory.rb
|
|
29
31
|
- examples/line.rb
|
|
30
32
|
- examples/new.rb
|
|
31
33
|
- examples/use.rb
|
|
@@ -59,5 +61,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
59
61
|
requirements: []
|
|
60
62
|
rubygems_version: 3.7.2
|
|
61
63
|
specification_version: 4
|
|
62
|
-
summary: A trusted number is a number whose value will not change secretly.
|
|
64
|
+
summary: 'A trusted number is a number whose value will not change secretly. For example
|
|
65
|
+
(base 10): 0.1 + 0.2 is 0.3.'
|
|
63
66
|
test_files: []
|