rbs 3.7.0 → 3.8.0.pre.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/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +7 -7
- data/CHANGELOG.md +52 -0
- data/core/array.rbs +1743 -1580
- data/core/basic_object.rbs +38 -35
- data/core/comparable.rbs +1 -1
- data/core/complex.rbs +165 -93
- data/core/data.rbs +1 -1
- data/core/dir.rbs +1 -17
- data/core/encoding.rbs +12 -6
- data/core/enumerable.rbs +270 -266
- data/core/enumerator.rbs +0 -2
- data/core/env.rbs +1 -1
- data/core/errno.rbs +33 -16
- data/core/errors.rbs +2 -2
- data/core/exception.rbs +236 -170
- data/core/fiber.rbs +3 -2
- data/core/file.rbs +32 -74
- data/core/float.rbs +125 -72
- data/core/gc.rbs +138 -40
- data/core/hash.rbs +120 -141
- data/core/integer.rbs +79 -50
- data/core/io/buffer.rbs +49 -43
- data/core/io.rbs +97 -144
- data/core/kernel.rbs +290 -200
- data/core/match_data.rbs +76 -2
- data/core/math.rbs +0 -36
- data/core/module.rbs +28 -23
- data/core/nil_class.rbs +0 -3
- data/core/numeric.rbs +100 -103
- data/core/object.rbs +0 -4
- data/core/object_space/weak_key_map.rbs +3 -4
- data/core/object_space.rbs +3 -3
- data/core/proc.rbs +0 -2
- data/core/process.rbs +109 -57
- data/core/ractor.rbs +37 -4
- data/core/range.rbs +114 -87
- data/core/rational.rbs +0 -2
- data/core/rbs/unnamed/argf.rbs +234 -33
- data/core/rbs/unnamed/env_class.rbs +35 -53
- data/core/rbs/unnamed/random.rbs +1 -2
- data/core/regexp.rbs +4 -52
- data/core/ruby_vm.rbs +88 -9
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +0 -5
- data/core/rubygems/platform.rbs +0 -9
- data/core/rubygems/rubygems.rbs +0 -5
- data/core/rubygems/version.rbs +6 -6
- data/core/set.rbs +3 -15
- data/core/string.rbs +130 -136
- data/core/struct.rbs +6 -18
- data/core/symbol.rbs +14 -21
- data/core/thread.rbs +32 -35
- data/core/time.rbs +127 -50
- data/core/trace_point.rbs +16 -0
- data/core/true_class.rbs +0 -1
- data/core/warning.rbs +9 -2
- data/docs/architecture.md +1 -1
- data/docs/syntax.md +1 -1
- data/ext/rbs_extension/location.c +29 -19
- data/ext/rbs_extension/parser.c +267 -292
- data/ext/rbs_extension/parserstate.c +56 -22
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/rdoc_source.rb +2 -2
- data/lib/rbs/cli/diff.rb +3 -3
- data/lib/rbs/cli/validate.rb +1 -1
- data/lib/rbs/cli.rb +13 -13
- data/lib/rbs/collection/config.rb +3 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/namespace.rb +1 -0
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +11 -8
- data/lib/rbs/prototype/rbi.rb +9 -5
- data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
- data/lib/rbs/prototype/runtime.rb +4 -5
- data/lib/rbs/type_name.rb +14 -9
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/validator.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +4 -0
- data/sig/ancestor_graph.rbs +4 -4
- data/sig/namespace.rbs +2 -3
- data/sig/resolver/constant_resolver.rbs +2 -2
- data/sig/resolver/context.rbs +1 -1
- data/sig/type_alias_regularity.rbs +5 -5
- data/sig/typename.rbs +8 -5
- data/sig/use_map.rbs +1 -1
- data/sig/validator.rbs +2 -2
- data/stdlib/base64/0/base64.rbs +0 -9
- data/stdlib/benchmark/0/benchmark.rbs +11 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
- data/stdlib/cgi/0/core.rbs +47 -0
- data/stdlib/coverage/0/coverage.rbs +0 -3
- data/stdlib/csv/0/csv.rbs +18 -58
- data/stdlib/date/0/date.rbs +4 -19
- data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
- data/stdlib/digest/0/digest.rbs +25 -2
- data/stdlib/erb/0/erb.rbs +0 -1
- data/stdlib/etc/0/etc.rbs +51 -34
- data/stdlib/fileutils/0/fileutils.rbs +3 -44
- data/stdlib/io-console/0/io-console.rbs +69 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
- data/stdlib/json/0/json.rbs +56 -71
- data/stdlib/logger/0/log_device.rbs +1 -1
- data/stdlib/logger/0/logger.rbs +3 -18
- data/stdlib/net-http/0/net-http.rbs +19 -77
- data/stdlib/nkf/0/nkf.rbs +30 -0
- data/stdlib/objspace/0/objspace.rbs +1 -2
- data/stdlib/observable/0/observable.rbs +1 -1
- data/stdlib/open-uri/0/open-uri.rbs +52 -0
- data/stdlib/open3/0/open3.rbs +0 -8
- data/stdlib/openssl/0/openssl.rbs +136 -69
- data/stdlib/optparse/0/optparse.rbs +58 -18
- data/stdlib/pathname/0/pathname.rbs +2 -8
- data/stdlib/pp/0/pp.rbs +3 -1
- data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
- data/stdlib/pstore/0/pstore.rbs +0 -6
- data/stdlib/psych/0/psych.rbs +15 -4
- data/stdlib/pty/0/pty.rbs +46 -4
- data/stdlib/rdoc/0/code_object.rbs +0 -4
- data/stdlib/rdoc/0/markup.rbs +10 -12
- data/stdlib/rdoc/0/rdoc.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +8 -3
- data/stdlib/ripper/0/ripper.rbs +0 -2
- data/stdlib/securerandom/0/securerandom.rbs +0 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -1
- data/stdlib/socket/0/addrinfo.rbs +0 -1
- data/stdlib/socket/0/basic_socket.rbs +0 -5
- data/stdlib/socket/0/socket.rbs +49 -25
- data/stdlib/socket/0/tcp_server.rbs +0 -3
- data/stdlib/socket/0/tcp_socket.rbs +58 -3
- data/stdlib/socket/0/udp_socket.rbs +0 -1
- data/stdlib/socket/0/unix_server.rbs +0 -3
- data/stdlib/strscan/0/string_scanner.rbs +1265 -422
- data/stdlib/tempfile/0/tempfile.rbs +135 -28
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +11 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +11 -30
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +22 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/zlib/0/buf_error.rbs +1 -70
- data/stdlib/zlib/0/data_error.rbs +1 -70
- data/stdlib/zlib/0/deflate.rbs +8 -72
- data/stdlib/zlib/0/error.rbs +1 -70
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
- data/stdlib/zlib/0/gzip_file.rbs +1 -71
- data/stdlib/zlib/0/gzip_reader.rbs +3 -74
- data/stdlib/zlib/0/gzip_writer.rbs +1 -70
- data/stdlib/zlib/0/inflate.rbs +4 -71
- data/stdlib/zlib/0/mem_error.rbs +1 -70
- data/stdlib/zlib/0/need_dict.rbs +1 -70
- data/stdlib/zlib/0/stream_end.rbs +1 -70
- data/stdlib/zlib/0/stream_error.rbs +1 -70
- data/stdlib/zlib/0/version_error.rbs +1 -70
- data/stdlib/zlib/0/zlib.rbs +0 -2
- data/stdlib/zlib/0/zstream.rbs +4 -72
- metadata +4 -6
data/sig/resolver/context.rbs
CHANGED
|
@@ -9,7 +9,7 @@ module RBS
|
|
|
9
9
|
#
|
|
10
10
|
# Note that the `TypeName` must be an absolute type name.
|
|
11
11
|
#
|
|
12
|
-
# The following Ruby code has context of `[[nil, TypeName("::Foo")], false]` where
|
|
12
|
+
# The following Ruby code has context of `[[nil, TypeName.parse("::Foo")], false]` where
|
|
13
13
|
#
|
|
14
14
|
# * `Foo` is a class defined in RBS file
|
|
15
15
|
# * `Bar` is not defined in RBS files
|
|
@@ -20,9 +20,9 @@ module RBS
|
|
|
20
20
|
# ```rb
|
|
21
21
|
# validator = RBS::TypeAliasRegularity.validate(env: env)
|
|
22
22
|
#
|
|
23
|
-
# validator.nonregular?(TypeName("::foo")) # => nil
|
|
24
|
-
# validator.nonregular?(TypeName("::bar")) # => nil
|
|
25
|
-
# validator.nonregular?(TypeName("::baz")) # => TypeAliasRegularity::Diagnostic
|
|
23
|
+
# validator.nonregular?(TypeName.parse("::foo")) # => nil
|
|
24
|
+
# validator.nonregular?(TypeName.parse("::bar")) # => nil
|
|
25
|
+
# validator.nonregular?(TypeName.parse("::baz")) # => TypeAliasRegularity::Diagnostic
|
|
26
26
|
# ```
|
|
27
27
|
#
|
|
28
28
|
# A special case is when the type argument is `untyped`.
|
|
@@ -51,8 +51,8 @@ module RBS
|
|
|
51
51
|
# The type `t` is nonregular because it contains `t[T?]` on it's right hand side.
|
|
52
52
|
#
|
|
53
53
|
# ```
|
|
54
|
-
# diagnostic = validator.nonregular?(TypeName("::t"))
|
|
55
|
-
# diagnostic.type_name # => TypeName("::t")
|
|
54
|
+
# diagnostic = validator.nonregular?(TypeName.parse("::t"))
|
|
55
|
+
# diagnostic.type_name # => TypeName.parse("::t")
|
|
56
56
|
# diagnostic.nonregular_type # => t[T?]
|
|
57
57
|
# ```
|
|
58
58
|
#
|
data/sig/typename.rbs
CHANGED
|
@@ -57,9 +57,9 @@ module RBS
|
|
|
57
57
|
# Returns a new type name with a namespace appended to given namespace.
|
|
58
58
|
#
|
|
59
59
|
# ```rb
|
|
60
|
-
# TypeName("Hello").with_prefix(Namespace("World")) # => World::Hello
|
|
61
|
-
# TypeName("Foo::Bar").with_prefix(Namespace("::Hello")) # => ::Hello::Foo::Bar
|
|
62
|
-
# TypeName("::A::B").with_prefix(Namespace("C")) # => ::A::B
|
|
60
|
+
# TypeName.parse("Hello").with_prefix(Namespace("World")) # => World::Hello
|
|
61
|
+
# TypeName.parse("Foo::Bar").with_prefix(Namespace("::Hello")) # => ::Hello::Foo::Bar
|
|
62
|
+
# TypeName.parse("::A::B").with_prefix(Namespace("C")) # => ::A::B
|
|
63
63
|
# ```
|
|
64
64
|
#
|
|
65
65
|
def with_prefix: (Namespace namespace) -> TypeName
|
|
@@ -67,10 +67,13 @@ module RBS
|
|
|
67
67
|
def +: (TypeName) -> TypeName
|
|
68
68
|
|
|
69
69
|
def split: () -> Array[Symbol]
|
|
70
|
+
|
|
71
|
+
# Returns type name with given string representation.
|
|
72
|
+
def self.parse: (String name) -> RBS::TypeName
|
|
70
73
|
end
|
|
71
74
|
end
|
|
72
75
|
|
|
73
76
|
module Kernel
|
|
74
|
-
#
|
|
75
|
-
def TypeName: (String name) -> RBS::TypeName
|
|
77
|
+
# Deprecated: Use `RBS::TypeName.parse` instead
|
|
78
|
+
%a{steep:deprecated} def TypeName: (String name) -> RBS::TypeName
|
|
76
79
|
end
|
data/sig/use_map.rbs
CHANGED
data/sig/validator.rbs
CHANGED
|
@@ -2,7 +2,7 @@ module RBS
|
|
|
2
2
|
class Validator
|
|
3
3
|
attr_reader env: Environment
|
|
4
4
|
|
|
5
|
-
attr_reader resolver: Resolver::TypeNameResolver
|
|
5
|
+
attr_reader resolver: Resolver::TypeNameResolver?
|
|
6
6
|
|
|
7
7
|
attr_reader definition_builder: DefinitionBuilder
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ module RBS
|
|
|
10
10
|
|
|
11
11
|
attr_reader type_alias_regularity: TypeAliasRegularity
|
|
12
12
|
|
|
13
|
-
def initialize: (env: Environment, resolver: Resolver::TypeNameResolver) -> void
|
|
13
|
+
def initialize: (env: Environment, ?resolver: Resolver::TypeNameResolver?) -> void
|
|
14
14
|
|
|
15
15
|
# Validates the presence of type names and type application arity match.
|
|
16
16
|
#
|
data/stdlib/base64/0/base64.rbs
CHANGED
|
@@ -5,14 +5,12 @@
|
|
|
5
5
|
# printable ASCII characters.
|
|
6
6
|
# * Decoding such an encoded string.
|
|
7
7
|
#
|
|
8
|
-
#
|
|
9
8
|
# Base64 is commonly used in contexts where binary data is not allowed or
|
|
10
9
|
# supported:
|
|
11
10
|
#
|
|
12
11
|
# * Images in HTML or CSS files, or in URLs.
|
|
13
12
|
# * Email attachments.
|
|
14
13
|
#
|
|
15
|
-
#
|
|
16
14
|
# A Base64-encoded string is about one-third larger that its source. See the
|
|
17
15
|
# [Wikipedia article](https://en.wikipedia.org/wiki/Base64) for more
|
|
18
16
|
# information.
|
|
@@ -24,7 +22,6 @@
|
|
|
24
22
|
# * Whether "padding" is to be used.
|
|
25
23
|
# * Whether encoded strings are to contain newlines.
|
|
26
24
|
#
|
|
27
|
-
#
|
|
28
25
|
# Note: Examples on this page assume that the including program has executed:
|
|
29
26
|
#
|
|
30
27
|
# require 'base64'
|
|
@@ -45,22 +42,18 @@
|
|
|
45
42
|
# [RFC-4648-compliant](https://datatracker.ietf.org/doc/html/rfc4648);
|
|
46
43
|
# safe for URLs.
|
|
47
44
|
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
45
|
# If you are working with Base64-encoded strings that will come from or be put
|
|
51
46
|
# into URLs, you should choose this encoder-decoder pair of RFC-4648-compliant
|
|
52
47
|
# methods:
|
|
53
48
|
#
|
|
54
49
|
# * Base64.urlsafe_encode64 and Base64.urlsafe_decode64.
|
|
55
50
|
#
|
|
56
|
-
#
|
|
57
51
|
# Otherwise, you may choose any of the pairs in this module, including the pair
|
|
58
52
|
# above, or the RFC-2045-compliant pairs:
|
|
59
53
|
#
|
|
60
54
|
# * Base64.encode64 and Base64.decode64.
|
|
61
55
|
# * Base64.strict_encode64 and Base64.strict_decode64.
|
|
62
56
|
#
|
|
63
|
-
#
|
|
64
57
|
# ## Padding
|
|
65
58
|
#
|
|
66
59
|
# Base64-encoding changes a triplet of input bytes into a quartet of output
|
|
@@ -104,7 +97,6 @@
|
|
|
104
97
|
# # n = 2: 8 bytes => 12 characters.
|
|
105
98
|
# Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc="
|
|
106
99
|
#
|
|
107
|
-
#
|
|
108
100
|
# When padding is suppressed, for a positive integer *n*:
|
|
109
101
|
#
|
|
110
102
|
# * Input bytes of length *3n* generate unpadded output characters of length
|
|
@@ -131,7 +123,6 @@
|
|
|
131
123
|
# # m = 2: 8 bytes => 11 characters.
|
|
132
124
|
# Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc"
|
|
133
125
|
#
|
|
134
|
-
#
|
|
135
126
|
# **Padding in Decode Methods**
|
|
136
127
|
#
|
|
137
128
|
# All of the Base64 decode methods support (but do not require) padding.
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
|
47
47
|
# end
|
|
48
48
|
#
|
|
49
|
-
#
|
|
50
49
|
# The result:
|
|
51
50
|
#
|
|
52
51
|
# user system total real
|
|
@@ -241,7 +240,11 @@ module Benchmark
|
|
|
241
240
|
# rdoc-file=lib/benchmark.rb
|
|
242
241
|
# - realtime() { || ... }
|
|
243
242
|
# -->
|
|
244
|
-
# Returns the elapsed real time used to execute the given block.
|
|
243
|
+
# Returns the elapsed real time used to execute the given block. The unit of
|
|
244
|
+
# time is seconds.
|
|
245
|
+
#
|
|
246
|
+
# Benchmark.realtime { "a" * 1_000_000_000 }
|
|
247
|
+
# #=> 0.5098029999935534
|
|
245
248
|
#
|
|
246
249
|
def self?.realtime: () { () -> void } -> Float
|
|
247
250
|
|
|
@@ -366,17 +369,23 @@ module Benchmark
|
|
|
366
369
|
#
|
|
367
370
|
# `%u`
|
|
368
371
|
# : Replaced by the user CPU time, as reported by Tms#utime.
|
|
372
|
+
#
|
|
369
373
|
# `%y`
|
|
370
374
|
# : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
|
|
371
375
|
# "s*y*stem")
|
|
376
|
+
#
|
|
372
377
|
# `%U`
|
|
373
378
|
# : Replaced by the children's user CPU time, as reported by Tms#cutime
|
|
379
|
+
#
|
|
374
380
|
# `%Y`
|
|
375
381
|
# : Replaced by the children's system CPU time, as reported by Tms#cstime
|
|
382
|
+
#
|
|
376
383
|
# `%t`
|
|
377
384
|
# : Replaced by the total CPU time, as reported by Tms#total
|
|
385
|
+
#
|
|
378
386
|
# `%r`
|
|
379
387
|
# : Replaced by the elapsed real time, as reported by Tms#real
|
|
388
|
+
#
|
|
380
389
|
# `%n`
|
|
381
390
|
# : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
|
|
382
391
|
# "*n*ame")
|
|
@@ -1,155 +1,3 @@
|
|
|
1
|
-
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
|
2
|
-
# BigDecimal provides arbitrary-precision floating point decimal arithmetic.
|
|
3
|
-
#
|
|
4
|
-
# ## Introduction
|
|
5
|
-
#
|
|
6
|
-
# Ruby provides built-in support for arbitrary precision integer arithmetic.
|
|
7
|
-
#
|
|
8
|
-
# For example:
|
|
9
|
-
#
|
|
10
|
-
# 42**13 #=> 1265437718438866624512
|
|
11
|
-
#
|
|
12
|
-
# BigDecimal provides similar support for very large or very accurate floating
|
|
13
|
-
# point numbers.
|
|
14
|
-
#
|
|
15
|
-
# Decimal arithmetic is also useful for general calculation, because it provides
|
|
16
|
-
# the correct answers people expect--whereas normal binary floating point
|
|
17
|
-
# arithmetic often introduces subtle errors because of the conversion between
|
|
18
|
-
# base 10 and base 2.
|
|
19
|
-
#
|
|
20
|
-
# For example, try:
|
|
21
|
-
#
|
|
22
|
-
# sum = 0
|
|
23
|
-
# 10_000.times do
|
|
24
|
-
# sum = sum + 0.0001
|
|
25
|
-
# end
|
|
26
|
-
# print sum #=> 0.9999999999999062
|
|
27
|
-
#
|
|
28
|
-
# and contrast with the output from:
|
|
29
|
-
#
|
|
30
|
-
# require 'bigdecimal'
|
|
31
|
-
#
|
|
32
|
-
# sum = BigDecimal("0")
|
|
33
|
-
# 10_000.times do
|
|
34
|
-
# sum = sum + BigDecimal("0.0001")
|
|
35
|
-
# end
|
|
36
|
-
# print sum #=> 0.1E1
|
|
37
|
-
#
|
|
38
|
-
# Similarly:
|
|
39
|
-
#
|
|
40
|
-
# (BigDecimal("1.2") - BigDecimal("1.0")) == BigDecimal("0.2") #=> true
|
|
41
|
-
#
|
|
42
|
-
# (1.2 - 1.0) == 0.2 #=> false
|
|
43
|
-
#
|
|
44
|
-
# ## A Note About Precision
|
|
45
|
-
#
|
|
46
|
-
# For a calculation using a BigDecimal and another `value`, the precision of the
|
|
47
|
-
# result depends on the type of `value`:
|
|
48
|
-
#
|
|
49
|
-
# * If `value` is a Float, the precision is Float::DIG + 1.
|
|
50
|
-
# * If `value` is a Rational, the precision is larger than Float::DIG + 1.
|
|
51
|
-
# * If `value` is a BigDecimal, the precision is `value`'s precision in the
|
|
52
|
-
# internal representation, which is platform-dependent.
|
|
53
|
-
# * If `value` is other object, the precision is determined by the result of
|
|
54
|
-
# +BigDecimal(value)+.
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
# ## Special features of accurate decimal arithmetic
|
|
58
|
-
#
|
|
59
|
-
# Because BigDecimal is more accurate than normal binary floating point
|
|
60
|
-
# arithmetic, it requires some special values.
|
|
61
|
-
#
|
|
62
|
-
# ### Infinity
|
|
63
|
-
#
|
|
64
|
-
# BigDecimal sometimes needs to return infinity, for example if you divide a
|
|
65
|
-
# value by zero.
|
|
66
|
-
#
|
|
67
|
-
# BigDecimal("1.0") / BigDecimal("0.0") #=> Infinity
|
|
68
|
-
# BigDecimal("-1.0") / BigDecimal("0.0") #=> -Infinity
|
|
69
|
-
#
|
|
70
|
-
# You can represent infinite numbers to BigDecimal using the strings
|
|
71
|
-
# `'Infinity'`, `'+Infinity'` and `'-Infinity'` (case-sensitive)
|
|
72
|
-
#
|
|
73
|
-
# ### Not a Number
|
|
74
|
-
#
|
|
75
|
-
# When a computation results in an undefined value, the special value `NaN` (for
|
|
76
|
-
# 'not a number') is returned.
|
|
77
|
-
#
|
|
78
|
-
# Example:
|
|
79
|
-
#
|
|
80
|
-
# BigDecimal("0.0") / BigDecimal("0.0") #=> NaN
|
|
81
|
-
#
|
|
82
|
-
# You can also create undefined values.
|
|
83
|
-
#
|
|
84
|
-
# NaN is never considered to be the same as any other value, even NaN itself:
|
|
85
|
-
#
|
|
86
|
-
# n = BigDecimal('NaN')
|
|
87
|
-
# n == 0.0 #=> false
|
|
88
|
-
# n == n #=> false
|
|
89
|
-
#
|
|
90
|
-
# ### Positive and negative zero
|
|
91
|
-
#
|
|
92
|
-
# If a computation results in a value which is too small to be represented as a
|
|
93
|
-
# BigDecimal within the currently specified limits of precision, zero must be
|
|
94
|
-
# returned.
|
|
95
|
-
#
|
|
96
|
-
# If the value which is too small to be represented is negative, a BigDecimal
|
|
97
|
-
# value of negative zero is returned.
|
|
98
|
-
#
|
|
99
|
-
# BigDecimal("1.0") / BigDecimal("-Infinity") #=> -0.0
|
|
100
|
-
#
|
|
101
|
-
# If the value is positive, a value of positive zero is returned.
|
|
102
|
-
#
|
|
103
|
-
# BigDecimal("1.0") / BigDecimal("Infinity") #=> 0.0
|
|
104
|
-
#
|
|
105
|
-
# (See BigDecimal.mode for how to specify limits of precision.)
|
|
106
|
-
#
|
|
107
|
-
# Note that `-0.0` and `0.0` are considered to be the same for the purposes of
|
|
108
|
-
# comparison.
|
|
109
|
-
#
|
|
110
|
-
# Note also that in mathematics, there is no particular concept of negative or
|
|
111
|
-
# positive zero; true mathematical zero has no sign.
|
|
112
|
-
#
|
|
113
|
-
# ## bigdecimal/util
|
|
114
|
-
#
|
|
115
|
-
# When you require `bigdecimal/util`, the #to_d method will be available on
|
|
116
|
-
# BigDecimal and the native Integer, Float, Rational, and String classes:
|
|
117
|
-
#
|
|
118
|
-
# require 'bigdecimal/util'
|
|
119
|
-
#
|
|
120
|
-
# 42.to_d # => 0.42e2
|
|
121
|
-
# 0.5.to_d # => 0.5e0
|
|
122
|
-
# (2/3r).to_d(3) # => 0.667e0
|
|
123
|
-
# "0.5".to_d # => 0.5e0
|
|
124
|
-
#
|
|
125
|
-
# ## Methods for Working with JSON
|
|
126
|
-
#
|
|
127
|
-
# * [::json_create](rdoc-ref:BigDecimal.json_create): Returns a new BigDecimal
|
|
128
|
-
# object constructed from the given object.
|
|
129
|
-
# * [#as_json](rdoc-ref:BigDecimal#as_json): Returns a 2-element hash
|
|
130
|
-
# representing `self`.
|
|
131
|
-
# * [#to_json](rdoc-ref:BigDecimal#to_json): Returns a JSON string
|
|
132
|
-
# representing `self`.
|
|
133
|
-
#
|
|
134
|
-
#
|
|
135
|
-
# These methods are provided by the [JSON gem](https://github.com/flori/json).
|
|
136
|
-
# To make these methods available:
|
|
137
|
-
#
|
|
138
|
-
# require 'json/add/bigdecimal'
|
|
139
|
-
#
|
|
140
|
-
# * ## License
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
# Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>.
|
|
144
|
-
#
|
|
145
|
-
# BigDecimal is released under the Ruby and 2-clause BSD licenses. See
|
|
146
|
-
# LICENSE.txt for details.
|
|
147
|
-
#
|
|
148
|
-
# Maintained by mrkn <mrkn@mrkn.jp> and ruby-core members.
|
|
149
|
-
#
|
|
150
|
-
# Documented by zzak <zachary@zacharyscott.net>, mathew <meta@pobox.com>, and
|
|
151
|
-
# many other contributors.
|
|
152
|
-
#
|
|
153
1
|
class BigDecimal < Numeric
|
|
154
2
|
# <!--
|
|
155
3
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
@@ -208,14 +56,12 @@ class BigDecimal < Numeric
|
|
|
208
56
|
# * BigDecimal::EXCEPTION_ZERODIVIDE.
|
|
209
57
|
# * BigDecimal::EXCEPTION_ALL.
|
|
210
58
|
#
|
|
211
|
-
#
|
|
212
59
|
# Values for `setting` for exception handling:
|
|
213
60
|
#
|
|
214
61
|
# * `true`: sets the given `mode` to `true`.
|
|
215
62
|
# * `false`: sets the given `mode` to `false`.
|
|
216
63
|
# * `nil`: does not modify the mode settings.
|
|
217
64
|
#
|
|
218
|
-
#
|
|
219
65
|
# You can use method BigDecimal.save_exception_mode to temporarily change, and
|
|
220
66
|
# then automatically restore, exception modes.
|
|
221
67
|
#
|
|
@@ -226,7 +72,6 @@ class BigDecimal < Numeric
|
|
|
226
72
|
#
|
|
227
73
|
# * BigDecimal::ROUND_MODE
|
|
228
74
|
#
|
|
229
|
-
#
|
|
230
75
|
# You can use method BigDecimal.save_rounding_mode to temporarily change, and
|
|
231
76
|
# then automatically restore, the rounding mode.
|
|
232
77
|
#
|
|
@@ -240,7 +85,6 @@ class BigDecimal < Numeric
|
|
|
240
85
|
# * `false` (default): Returns `BigDecimal('NaN')`.
|
|
241
86
|
# * `true`: Raises FloatDomainError.
|
|
242
87
|
#
|
|
243
|
-
#
|
|
244
88
|
# Examples:
|
|
245
89
|
#
|
|
246
90
|
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
|
@@ -257,7 +101,6 @@ class BigDecimal < Numeric
|
|
|
257
101
|
# `BigDecimal('-Infinity')`.
|
|
258
102
|
# * `true`: Raises FloatDomainError.
|
|
259
103
|
#
|
|
260
|
-
#
|
|
261
104
|
# Examples:
|
|
262
105
|
#
|
|
263
106
|
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
|
@@ -275,7 +118,6 @@ class BigDecimal < Numeric
|
|
|
275
118
|
# * `false` (default): Returns `BigDecimal('0')` or `BigDecimal('-Infinity')`.
|
|
276
119
|
# * `true`: Raises FloatDomainError.
|
|
277
120
|
#
|
|
278
|
-
#
|
|
279
121
|
# Examples:
|
|
280
122
|
#
|
|
281
123
|
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
|
@@ -296,7 +138,6 @@ class BigDecimal < Numeric
|
|
|
296
138
|
# `BigDecimal('-Infinity')`.
|
|
297
139
|
# * `true`: Raises FloatDomainError.
|
|
298
140
|
#
|
|
299
|
-
#
|
|
300
141
|
# Examples:
|
|
301
142
|
#
|
|
302
143
|
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
|
@@ -317,7 +158,6 @@ class BigDecimal < Numeric
|
|
|
317
158
|
# `BigDecimal('-Infinity')`.
|
|
318
159
|
# * `true`: Raises FloatDomainError.
|
|
319
160
|
#
|
|
320
|
-
#
|
|
321
161
|
# Examples:
|
|
322
162
|
#
|
|
323
163
|
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
|
@@ -1030,16 +870,22 @@ class BigDecimal < Numeric
|
|
|
1030
870
|
#
|
|
1031
871
|
# BigDecimal::SIGN_NaN
|
|
1032
872
|
# : value is Not a Number
|
|
873
|
+
#
|
|
1033
874
|
# BigDecimal::SIGN_POSITIVE_ZERO
|
|
1034
875
|
# : value is +0
|
|
876
|
+
#
|
|
1035
877
|
# BigDecimal::SIGN_NEGATIVE_ZERO
|
|
1036
878
|
# : value is -0
|
|
879
|
+
#
|
|
1037
880
|
# BigDecimal::SIGN_POSITIVE_INFINITE
|
|
1038
881
|
# : value is +Infinity
|
|
882
|
+
#
|
|
1039
883
|
# BigDecimal::SIGN_NEGATIVE_INFINITE
|
|
1040
884
|
# : value is -Infinity
|
|
885
|
+
#
|
|
1041
886
|
# BigDecimal::SIGN_POSITIVE_FINITE
|
|
1042
887
|
# : value is positive
|
|
888
|
+
#
|
|
1043
889
|
# BigDecimal::SIGN_NEGATIVE_FINITE
|
|
1044
890
|
# : value is negative
|
|
1045
891
|
#
|
|
@@ -1403,8 +1249,6 @@ module Kernel
|
|
|
1403
1249
|
# * Raises an exception if keyword argument `exception` is `true`.
|
|
1404
1250
|
# * Returns `nil` if keyword argument `exception` is `false`.
|
|
1405
1251
|
#
|
|
1406
|
-
#
|
|
1407
|
-
#
|
|
1408
1252
|
# Raises an exception if `value` evaluates to a Float and `digits` is larger
|
|
1409
1253
|
# than Float::DIG + 1.
|
|
1410
1254
|
#
|
|
@@ -1713,11 +1557,11 @@ class Complex
|
|
|
1713
1557
|
# -->
|
|
1714
1558
|
# Returns the quotient of `self` and `numeric`:
|
|
1715
1559
|
#
|
|
1716
|
-
# Complex(2, 3) / Complex(2, 3) # => (
|
|
1717
|
-
# Complex(900) / Complex(1) # => (
|
|
1718
|
-
# Complex(-2, 9) / Complex(-9, 2) # => ((36/85)-(77/85)*i)
|
|
1719
|
-
# Complex(9, 8) / 4
|
|
1720
|
-
# Complex(20, 9) / 9.8
|
|
1560
|
+
# Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
|
|
1561
|
+
# Complex.rect(900) / Complex.rect(1) # => (900+0i)
|
|
1562
|
+
# Complex.rect(-2, 9) / Complex.rect(-9, 2) # => ((36/85)-(77/85)*i)
|
|
1563
|
+
# Complex.rect(9, 8) / 4 # => ((9/4)+2i)
|
|
1564
|
+
# Complex.rect(20, 9) / 9.8 # => (2.0408163265306123+0.9183673469387754i)
|
|
1721
1565
|
#
|
|
1722
1566
|
def /: (BigDecimal) -> Complex
|
|
1723
1567
|
| ...
|
|
@@ -1728,11 +1572,11 @@ class Complex
|
|
|
1728
1572
|
# -->
|
|
1729
1573
|
# Returns the product of `self` and `numeric`:
|
|
1730
1574
|
#
|
|
1731
|
-
# Complex(2, 3) * Complex(2, 3) # => (-5+12i)
|
|
1732
|
-
# Complex(900) * Complex(1) # => (900+0i)
|
|
1733
|
-
# Complex(-2, 9) * Complex(-9, 2) # => (0-85i)
|
|
1734
|
-
# Complex(9, 8) * 4
|
|
1735
|
-
# Complex(20, 9) * 9.8
|
|
1575
|
+
# Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
|
|
1576
|
+
# Complex.rect(900) * Complex.rect(1) # => (900+0i)
|
|
1577
|
+
# Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
|
|
1578
|
+
# Complex.rect(9, 8) * 4 # => (36+32i)
|
|
1579
|
+
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
1736
1580
|
#
|
|
1737
1581
|
def *: (BigDecimal) -> Complex
|
|
1738
1582
|
| ...
|
|
@@ -1743,11 +1587,11 @@ class Complex
|
|
|
1743
1587
|
# -->
|
|
1744
1588
|
# Returns the sum of `self` and `numeric`:
|
|
1745
1589
|
#
|
|
1746
|
-
# Complex(2, 3) + Complex(2, 3) # => (4+6i)
|
|
1747
|
-
# Complex(900) + Complex(1) # => (901+0i)
|
|
1748
|
-
# Complex(-2, 9) + Complex(-9, 2) # => (-11+11i)
|
|
1749
|
-
# Complex(9, 8) + 4
|
|
1750
|
-
# Complex(20, 9) + 9.8
|
|
1590
|
+
# Complex.rect(2, 3) + Complex.rect(2, 3) # => (4+6i)
|
|
1591
|
+
# Complex.rect(900) + Complex.rect(1) # => (901+0i)
|
|
1592
|
+
# Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
|
|
1593
|
+
# Complex.rect(9, 8) + 4 # => (13+8i)
|
|
1594
|
+
# Complex.rect(20, 9) + 9.8 # => (29.8+9i)
|
|
1751
1595
|
#
|
|
1752
1596
|
def +: (BigDecimal) -> Complex
|
|
1753
1597
|
| ...
|
|
@@ -1758,11 +1602,11 @@ class Complex
|
|
|
1758
1602
|
# -->
|
|
1759
1603
|
# Returns the difference of `self` and `numeric`:
|
|
1760
1604
|
#
|
|
1761
|
-
# Complex(2, 3) - Complex(2, 3) # => (0+0i)
|
|
1762
|
-
# Complex(900) - Complex(1) # => (899+0i)
|
|
1763
|
-
# Complex(-2, 9) - Complex(-9, 2) # => (7+7i)
|
|
1764
|
-
# Complex(9, 8) - 4
|
|
1765
|
-
# Complex(20, 9) - 9.8
|
|
1605
|
+
# Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
|
|
1606
|
+
# Complex.rect(900) - Complex.rect(1) # => (899+0i)
|
|
1607
|
+
# Complex.rect(-2, 9) - Complex.rect(-9, 2) # => (7+7i)
|
|
1608
|
+
# Complex.rect(9, 8) - 4 # => (5+8i)
|
|
1609
|
+
# Complex.rect(20, 9) - 9.8 # => (10.2+9i)
|
|
1766
1610
|
#
|
|
1767
1611
|
def -: (BigDecimal) -> Complex
|
|
1768
1612
|
| ...
|