rbs 3.10.0 → 4.0.0.dev.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 +24 -35
- data/.github/workflows/typecheck.yml +3 -1
- data/.github/workflows/windows.yml +2 -2
- data/.gitignore +0 -4
- data/CHANGELOG.md +0 -88
- data/README.md +1 -38
- data/Rakefile +20 -142
- data/Steepfile +1 -0
- data/config.yml +43 -1
- data/core/array.rbs +46 -100
- data/core/complex.rbs +21 -32
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +9 -6
- data/core/enumerable.rbs +3 -90
- data/core/enumerator.rbs +1 -18
- data/core/errno.rbs +0 -8
- data/core/errors.rbs +1 -28
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +4 -5
- data/core/file.rbs +12 -27
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +22 -209
- data/core/gc.rbs +281 -417
- data/core/hash.rbs +727 -1024
- data/core/integer.rbs +38 -78
- data/core/io/buffer.rbs +7 -18
- data/core/io/wait.rbs +33 -11
- data/core/io.rbs +12 -14
- data/core/kernel.rbs +51 -57
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +3 -42
- data/core/method.rbs +6 -14
- data/core/module.rbs +17 -88
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +15 -21
- data/core/proc.rbs +8 -15
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +437 -278
- data/core/range.rbs +8 -7
- data/core/rational.rbs +24 -37
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +2 -4
- data/core/regexp.rbs +20 -25
- data/core/ruby_vm.rbs +4 -6
- data/core/rubygems/errors.rbs +70 -3
- data/core/rubygems/rubygems.rbs +79 -11
- data/core/rubygems/version.rbs +3 -2
- data/core/set.rbs +359 -488
- data/core/string.rbs +1228 -3153
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +29 -92
- data/core/time.rbs +9 -35
- data/core/trace_point.rbs +4 -7
- data/core/unbound_method.rbs +6 -14
- data/docs/collection.md +2 -2
- data/docs/gem.md +1 -0
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1077 -944
- data/ext/rbs_extension/ast_translation.h +0 -7
- data/ext/rbs_extension/class_constants.c +83 -71
- data/ext/rbs_extension/class_constants.h +7 -4
- data/ext/rbs_extension/extconf.rb +2 -24
- data/ext/rbs_extension/legacy_location.c +172 -173
- data/ext/rbs_extension/legacy_location.h +3 -8
- data/ext/rbs_extension/main.c +289 -239
- data/ext/rbs_extension/rbs_extension.h +0 -3
- data/ext/rbs_extension/rbs_string_bridging.h +0 -4
- data/include/rbs/ast.h +98 -37
- data/include/rbs/defines.h +12 -38
- data/include/rbs/lexer.h +114 -126
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +37 -21
- data/include/rbs/string.h +5 -3
- data/include/rbs/util/rbs_allocator.h +19 -40
- data/include/rbs/util/rbs_assert.h +1 -12
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -3
- data/include/rbs/util/rbs_unescape.h +1 -2
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +40 -35
- data/lib/rbs/cli.rb +5 -6
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +244 -218
- data/lib/rbs/environment_loader.rb +3 -3
- data/lib/rbs/errors.rb +5 -4
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -6
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +38 -124
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +0 -14
- data/lib/rbs/types.rb +1 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +13 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +28 -133
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/manifest.yaml +1 -0
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -20
- data/sig/resolver/type_name_resolver.rbs +7 -38
- data/sig/source.rbs +48 -0
- data/sig/types.rbs +1 -4
- data/src/ast.c +290 -201
- data/src/lexer.c +2813 -2902
- data/src/lexer.re +4 -0
- data/src/lexstate.c +155 -169
- data/src/location.c +40 -40
- data/src/parser.c +2665 -2433
- data/src/string.c +48 -0
- data/src/util/rbs_allocator.c +77 -80
- data/src/util/rbs_assert.c +10 -10
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +15 -13
- data/src/util/rbs_encoding.c +4062 -20097
- data/src/util/rbs_unescape.c +48 -85
- data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
- data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
- data/stdlib/cgi/0/core.rbs +396 -2
- data/stdlib/cgi/0/manifest.yaml +0 -1
- data/stdlib/coverage/0/coverage.rbs +1 -3
- data/stdlib/date/0/date.rbs +59 -67
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +7 -10
- data/stdlib/erb/0/erb.rbs +347 -737
- data/stdlib/fileutils/0/fileutils.rbs +13 -18
- data/stdlib/forwardable/0/forwardable.rbs +0 -3
- data/stdlib/json/0/json.rbs +48 -68
- data/stdlib/net-http/0/net-http.rbs +0 -3
- data/stdlib/objspace/0/objspace.rbs +4 -9
- data/stdlib/open-uri/0/open-uri.rbs +0 -40
- data/stdlib/openssl/0/openssl.rbs +228 -331
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +68 -25
- data/stdlib/ripper/0/ripper.rbs +2 -5
- data/stdlib/singleton/0/singleton.rbs +0 -3
- data/stdlib/socket/0/socket.rbs +1 -13
- data/stdlib/socket/0/tcp_socket.rbs +2 -10
- data/stdlib/stringio/0/stringio.rbs +85 -1176
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +7 -63
- data/stdlib/tsort/0/cyclic.rbs +0 -3
- data/stdlib/uri/0/common.rbs +2 -11
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +16 -17
- data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
- data/stdlib/zlib/0/zstream.rbs +0 -1
- metadata +40 -12
- data/.clang-format +0 -74
- data/.clangd +0 -2
- data/.github/workflows/c-check.yml +0 -54
- data/core/ruby.rbs +0 -53
- data/docs/aliases.md +0 -79
- data/docs/encoding.md +0 -56
- data/ext/rbs_extension/compat.h +0 -10
- data/stdlib/cgi-escape/0/escape.rbs +0 -153
data/src/util/rbs_unescape.c
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#include "rbs/util/rbs_unescape.h"
|
|
2
|
-
#include "rbs/util/rbs_encoding.h"
|
|
3
2
|
#include <string.h>
|
|
4
3
|
#include <stdlib.h>
|
|
5
4
|
#include <ctype.h>
|
|
@@ -7,26 +6,26 @@
|
|
|
7
6
|
// Define the escape character mappings
|
|
8
7
|
// TODO: use a switch instead
|
|
9
8
|
static const struct {
|
|
10
|
-
const char
|
|
11
|
-
const char
|
|
9
|
+
const char* from;
|
|
10
|
+
const char* to;
|
|
12
11
|
} TABLE[] = {
|
|
13
|
-
{
|
|
14
|
-
{
|
|
15
|
-
{
|
|
16
|
-
{
|
|
17
|
-
{
|
|
18
|
-
{
|
|
19
|
-
{
|
|
20
|
-
{
|
|
21
|
-
{
|
|
22
|
-
{
|
|
23
|
-
{
|
|
24
|
-
{
|
|
25
|
-
{
|
|
12
|
+
{"\\a", "\a"},
|
|
13
|
+
{"\\b", "\b"},
|
|
14
|
+
{"\\e", "\033"},
|
|
15
|
+
{"\\f", "\f"},
|
|
16
|
+
{"\\n", "\n"},
|
|
17
|
+
{"\\r", "\r"},
|
|
18
|
+
{"\\s", " "},
|
|
19
|
+
{"\\t", "\t"},
|
|
20
|
+
{"\\v", "\v"},
|
|
21
|
+
{"\\\"", "\""},
|
|
22
|
+
{"\\'", "'"},
|
|
23
|
+
{"\\\\", "\\"},
|
|
24
|
+
{"\\", ""}
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
// Helper function to convert hex string to integer
|
|
29
|
-
static int hex_to_int(const char
|
|
28
|
+
static int hex_to_int(const char* hex, int length) {
|
|
30
29
|
int result = 0;
|
|
31
30
|
for (int i = 0; i < length; i++) {
|
|
32
31
|
result = result * 16 + (isdigit(hex[i]) ? hex[i] - '0' : tolower(hex[i]) - 'a' + 10);
|
|
@@ -35,7 +34,7 @@ static int hex_to_int(const char *hex, int length) {
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
// Helper function to convert octal string to integer
|
|
38
|
-
static int octal_to_int(const char
|
|
37
|
+
static int octal_to_int(const char* octal, int length) {
|
|
39
38
|
int result = 0;
|
|
40
39
|
for (int i = 0; i < length; i++) {
|
|
41
40
|
result = result * 8 + (octal[i] - '0');
|
|
@@ -43,82 +42,45 @@ static int octal_to_int(const char *octal, int length) {
|
|
|
43
42
|
return result;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (codepoint <= 0x7F) {
|
|
55
|
-
buf[start] = codepoint & 0x7F;
|
|
56
|
-
return 1;
|
|
57
|
-
} else if (codepoint <= 0x7FF) {
|
|
58
|
-
buf[start + 0] = 0xC0 | ((codepoint >> 6) & 0x1F);
|
|
59
|
-
buf[start + 1] = 0x80 | (codepoint & 0x3F);
|
|
60
|
-
return 2;
|
|
61
|
-
} else if (codepoint <= 0xFFFF) {
|
|
62
|
-
buf[start + 0] = 0xE0 | ((codepoint >> 12) & 0x0F);
|
|
63
|
-
buf[start + 1] = 0x80 | ((codepoint >> 6) & 0x3F);
|
|
64
|
-
buf[start + 2] = 0x80 | (codepoint & 0x3F);
|
|
65
|
-
return 3;
|
|
66
|
-
} else if (codepoint <= 0x10FFFF) {
|
|
67
|
-
buf[start + 0] = 0xF0 | ((codepoint >> 18) & 0x07);
|
|
68
|
-
buf[start + 1] = 0x80 | ((codepoint >> 12) & 0x3F);
|
|
69
|
-
buf[start + 2] = 0x80 | ((codepoint >> 6) & 0x3F);
|
|
70
|
-
buf[start + 3] = 0x80 | (codepoint & 0x3F);
|
|
71
|
-
return 4;
|
|
72
|
-
} else {
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
45
|
+
int rbs_utf8_codelen(unsigned int c) {
|
|
46
|
+
if (c <= 0x7F) return 1;
|
|
47
|
+
if (c <= 0x7FF) return 2;
|
|
48
|
+
if (c <= 0xFFFF) return 3;
|
|
49
|
+
if (c <= 0x10FFFF) return 4;
|
|
50
|
+
return 1; // Invalid Unicode codepoint, treat as 1 byte
|
|
75
51
|
}
|
|
76
52
|
|
|
77
|
-
rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t string, bool is_double_quote
|
|
53
|
+
rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t string, bool is_double_quote) {
|
|
78
54
|
if (!string.start) return RBS_STRING_NULL;
|
|
79
55
|
|
|
80
56
|
size_t len = string.end - string.start;
|
|
81
|
-
const char
|
|
57
|
+
const char* input = string.start;
|
|
82
58
|
|
|
83
|
-
|
|
84
|
-
char *output = rbs_allocator_alloc_many(allocator, len + 1, char);
|
|
59
|
+
char* output = rbs_allocator_alloc_many(allocator, len + 1, char);
|
|
85
60
|
if (!output) return RBS_STRING_NULL;
|
|
86
61
|
|
|
87
62
|
size_t i = 0, j = 0;
|
|
88
63
|
while (i < len) {
|
|
89
64
|
if (input[i] == '\\' && i + 1 < len) {
|
|
90
65
|
if (is_double_quote) {
|
|
91
|
-
if (isdigit(input[i
|
|
66
|
+
if (isdigit(input[i+1])) {
|
|
92
67
|
// Octal escape
|
|
93
68
|
int octal_len = 1;
|
|
94
|
-
while (octal_len < 3 && i + 1 + octal_len < len && isdigit(input[i + 1 + octal_len]))
|
|
95
|
-
octal_len++;
|
|
69
|
+
while (octal_len < 3 && i + 1 + octal_len < len && isdigit(input[i + 1 + octal_len])) octal_len++;
|
|
96
70
|
int value = octal_to_int(input + i + 1, octal_len);
|
|
97
|
-
output[j++] = (char)
|
|
71
|
+
output[j++] = (char)value;
|
|
98
72
|
i += octal_len + 1;
|
|
99
|
-
} else if (input[i
|
|
73
|
+
} else if (input[i+1] == 'x' && i + 3 < len) {
|
|
100
74
|
// Hex escape
|
|
101
|
-
int hex_len = isxdigit(input[i
|
|
75
|
+
int hex_len = isxdigit(input[i+3]) ? 2 : 1;
|
|
102
76
|
int value = hex_to_int(input + i + 2, hex_len);
|
|
103
|
-
output[j++] = (char)
|
|
77
|
+
output[j++] = (char)value;
|
|
104
78
|
i += hex_len + 2;
|
|
105
|
-
} else if (input[i
|
|
79
|
+
} else if (input[i+1] == 'u' && i + 5 < len) {
|
|
106
80
|
// Unicode escape
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
int value = hex_to_int(input + i + 2, 4);
|
|
111
|
-
j += rbs_utf8_fill_codepoint(output, j, len + 1, value);
|
|
112
|
-
i += 6;
|
|
113
|
-
} else {
|
|
114
|
-
// Copy the escape sequence as-is
|
|
115
|
-
output[j++] = input[i++];
|
|
116
|
-
output[j++] = input[i++];
|
|
117
|
-
output[j++] = input[i++];
|
|
118
|
-
output[j++] = input[i++];
|
|
119
|
-
output[j++] = input[i++];
|
|
120
|
-
output[j++] = input[i++];
|
|
121
|
-
}
|
|
81
|
+
int value = hex_to_int(input + i + 2, 4);
|
|
82
|
+
output[j++] = (char)value;
|
|
83
|
+
i += 6;
|
|
122
84
|
} else {
|
|
123
85
|
// Other escapes
|
|
124
86
|
int found = 0;
|
|
@@ -136,8 +98,8 @@ rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t stri
|
|
|
136
98
|
}
|
|
137
99
|
} else {
|
|
138
100
|
/* Single quote: only escape ' and \ */
|
|
139
|
-
if (input[i
|
|
140
|
-
output[j++] = input[i
|
|
101
|
+
if (input[i+1] == '\'' || input[i+1] == '\\') {
|
|
102
|
+
output[j++] = input[i+1];
|
|
141
103
|
i += 2;
|
|
142
104
|
} else {
|
|
143
105
|
output[j++] = input[i++];
|
|
@@ -151,17 +113,18 @@ rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t stri
|
|
|
151
113
|
return rbs_string_new(output, output + j);
|
|
152
114
|
}
|
|
153
115
|
|
|
154
|
-
rbs_string_t rbs_unquote_string(rbs_allocator_t *allocator, rbs_string_t input
|
|
155
|
-
unsigned int first_char = input
|
|
156
|
-
|
|
157
|
-
const char *new_start = input.start;
|
|
158
|
-
const char *new_end = input.end;
|
|
116
|
+
rbs_string_t rbs_unquote_string(rbs_allocator_t *allocator, rbs_string_t input) {
|
|
117
|
+
unsigned int first_char = rbs_utf8_string_to_codepoint(input);
|
|
118
|
+
size_t byte_length = rbs_string_len(input);
|
|
159
119
|
|
|
120
|
+
ptrdiff_t start_offset = 0;
|
|
160
121
|
if (first_char == '"' || first_char == '\'' || first_char == '`') {
|
|
161
|
-
|
|
162
|
-
|
|
122
|
+
int bs = rbs_utf8_codelen(first_char);
|
|
123
|
+
start_offset += bs;
|
|
124
|
+
byte_length -= 2 * bs;
|
|
163
125
|
}
|
|
164
126
|
|
|
165
|
-
|
|
166
|
-
|
|
127
|
+
const char *new_start = input.start + start_offset;
|
|
128
|
+
rbs_string_t string = rbs_string_new(new_start, new_start + byte_length);
|
|
129
|
+
return unescape_string(allocator, string, first_char == '"');
|
|
167
130
|
}
|
|
@@ -609,7 +609,7 @@ class BigDecimal < Numeric
|
|
|
609
609
|
# The quotient q is (a/b).floor, and the modulus is the amount that must be
|
|
610
610
|
# added to q * b to get a.
|
|
611
611
|
#
|
|
612
|
-
def divmod: (Numeric) -> [
|
|
612
|
+
def divmod: (Numeric) -> [ BigDecimal, BigDecimal ]
|
|
613
613
|
|
|
614
614
|
# <!--
|
|
615
615
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
@@ -783,6 +783,20 @@ class BigDecimal < Numeric
|
|
|
783
783
|
#
|
|
784
784
|
def power: (Numeric n, int prec) -> BigDecimal
|
|
785
785
|
|
|
786
|
+
# <!--
|
|
787
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
788
|
+
# - precs -> array
|
|
789
|
+
# -->
|
|
790
|
+
# Returns an Array of two Integer values that represent platform-dependent
|
|
791
|
+
# internal storage properties.
|
|
792
|
+
#
|
|
793
|
+
# This method is deprecated and will be removed in the future. Instead, use
|
|
794
|
+
# BigDecimal#n_significant_digits for obtaining the number of significant digits
|
|
795
|
+
# in scientific notation, and BigDecimal#precision for obtaining the number of
|
|
796
|
+
# digits in decimal notation.
|
|
797
|
+
#
|
|
798
|
+
def precs: () -> [ Integer, Integer ]
|
|
799
|
+
|
|
786
800
|
# <!--
|
|
787
801
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
788
802
|
# - quo(value) -> bigdecimal
|
|
@@ -1260,35 +1274,33 @@ class Integer
|
|
|
1260
1274
|
|
|
1261
1275
|
# <!--
|
|
1262
1276
|
# rdoc-file=numeric.c
|
|
1263
|
-
# - self /
|
|
1277
|
+
# - self / numeric -> numeric_result
|
|
1264
1278
|
# -->
|
|
1265
|
-
#
|
|
1266
|
-
#
|
|
1267
|
-
# For integer `other`, truncates the result to an integer:
|
|
1279
|
+
# Performs division; for integer `numeric`, truncates the result to an integer:
|
|
1268
1280
|
#
|
|
1269
|
-
#
|
|
1270
|
-
#
|
|
1271
|
-
#
|
|
1272
|
-
#
|
|
1281
|
+
# 4 / 3 # => 1
|
|
1282
|
+
# 4 / -3 # => -2
|
|
1283
|
+
# -4 / 3 # => -2
|
|
1284
|
+
# -4 / -3 # => 1
|
|
1273
1285
|
#
|
|
1274
|
-
#
|
|
1286
|
+
# For other +numeric+, returns non-integer result:
|
|
1275
1287
|
#
|
|
1276
|
-
#
|
|
1277
|
-
#
|
|
1278
|
-
#
|
|
1288
|
+
# 4 / 3.0 # => 1.3333333333333333
|
|
1289
|
+
# 4 / Rational(3, 1) # => (4/3)
|
|
1290
|
+
# 4 / Complex(3, 0) # => ((4/3)+0i)
|
|
1279
1291
|
#
|
|
1280
1292
|
def /: (BigDecimal) -> BigDecimal
|
|
1281
1293
|
| ...
|
|
1282
1294
|
|
|
1283
1295
|
# <!--
|
|
1284
1296
|
# rdoc-file=numeric.c
|
|
1285
|
-
# - self *
|
|
1297
|
+
# - self * numeric -> numeric_result
|
|
1286
1298
|
# -->
|
|
1287
|
-
#
|
|
1299
|
+
# Performs multiplication:
|
|
1288
1300
|
#
|
|
1289
1301
|
# 4 * 2 # => 8
|
|
1290
|
-
# -4 * 2 # => -8
|
|
1291
1302
|
# 4 * -2 # => -8
|
|
1303
|
+
# -4 * 2 # => -8
|
|
1292
1304
|
# 4 * 2.0 # => 8.0
|
|
1293
1305
|
# 4 * Rational(1, 3) # => (4/3)
|
|
1294
1306
|
# 4 * Complex(2, 0) # => (8+0i)
|
|
@@ -1298,29 +1310,25 @@ class Integer
|
|
|
1298
1310
|
|
|
1299
1311
|
# <!--
|
|
1300
1312
|
# rdoc-file=numeric.c
|
|
1301
|
-
# - self +
|
|
1313
|
+
# - self + numeric -> numeric_result
|
|
1302
1314
|
# -->
|
|
1303
|
-
#
|
|
1304
|
-
#
|
|
1305
|
-
# 1 + 1 # => 2
|
|
1306
|
-
# 1 + -1 # => 0
|
|
1307
|
-
# 1 + 0 # => 1
|
|
1308
|
-
# 1 + -2 # => -1
|
|
1309
|
-
# 1 + Complex(1, 0) # => (2+0i)
|
|
1310
|
-
# 1 + Rational(1, 1) # => (2/1)
|
|
1315
|
+
# Performs addition:
|
|
1311
1316
|
#
|
|
1312
|
-
#
|
|
1313
|
-
#
|
|
1314
|
-
#
|
|
1317
|
+
# 2 + 2 # => 4
|
|
1318
|
+
# -2 + 2 # => 0
|
|
1319
|
+
# -2 + -2 # => -4
|
|
1320
|
+
# 2 + 2.0 # => 4.0
|
|
1321
|
+
# 2 + Rational(2, 1) # => (4/1)
|
|
1322
|
+
# 2 + Complex(2, 0) # => (4+0i)
|
|
1315
1323
|
#
|
|
1316
1324
|
def +: (BigDecimal) -> BigDecimal
|
|
1317
1325
|
| ...
|
|
1318
1326
|
|
|
1319
1327
|
# <!--
|
|
1320
1328
|
# rdoc-file=numeric.c
|
|
1321
|
-
# - self -
|
|
1329
|
+
# - self - numeric -> numeric_result
|
|
1322
1330
|
# -->
|
|
1323
|
-
#
|
|
1331
|
+
# Performs subtraction:
|
|
1324
1332
|
#
|
|
1325
1333
|
# 4 - 2 # => 2
|
|
1326
1334
|
# -4 - 2 # => -6
|
|
@@ -1360,7 +1368,7 @@ class Float
|
|
|
1360
1368
|
# rdoc-file=numeric.c
|
|
1361
1369
|
# - self / other -> numeric
|
|
1362
1370
|
# -->
|
|
1363
|
-
# Returns the
|
|
1371
|
+
# Returns a new Float which is the result of dividing `self` by `other`:
|
|
1364
1372
|
#
|
|
1365
1373
|
# f = 3.14
|
|
1366
1374
|
# f / 2 # => 1.57
|
|
@@ -1375,7 +1383,7 @@ class Float
|
|
|
1375
1383
|
# rdoc-file=numeric.c
|
|
1376
1384
|
# - self * other -> numeric
|
|
1377
1385
|
# -->
|
|
1378
|
-
# Returns the
|
|
1386
|
+
# Returns a new Float which is the product of `self` and `other`:
|
|
1379
1387
|
#
|
|
1380
1388
|
# f = 3.14
|
|
1381
1389
|
# f * 2 # => 6.28
|
|
@@ -1388,20 +1396,15 @@ class Float
|
|
|
1388
1396
|
|
|
1389
1397
|
# <!--
|
|
1390
1398
|
# rdoc-file=numeric.c
|
|
1391
|
-
# - self + other ->
|
|
1399
|
+
# - self + other -> numeric
|
|
1392
1400
|
# -->
|
|
1393
|
-
# Returns the sum of `self` and `other
|
|
1394
|
-
#
|
|
1395
|
-
# 3.14 + 0 # => 3.14
|
|
1396
|
-
# 3.14 + 1 # => 4.140000000000001
|
|
1397
|
-
# -3.14 + 0 # => -3.14
|
|
1398
|
-
# -3.14 + 1 # => -2.14
|
|
1401
|
+
# Returns a new Float which is the sum of `self` and `other`:
|
|
1399
1402
|
#
|
|
1400
|
-
#
|
|
1401
|
-
#
|
|
1402
|
-
#
|
|
1403
|
-
#
|
|
1404
|
-
#
|
|
1403
|
+
# f = 3.14
|
|
1404
|
+
# f + 1 # => 4.140000000000001
|
|
1405
|
+
# f + 1.0 # => 4.140000000000001
|
|
1406
|
+
# f + Rational(1, 1) # => 4.140000000000001
|
|
1407
|
+
# f + Complex(1, 0) # => (4.140000000000001+0i)
|
|
1405
1408
|
#
|
|
1406
1409
|
def +: (BigDecimal) -> BigDecimal
|
|
1407
1410
|
| ...
|
|
@@ -1410,7 +1413,7 @@ class Float
|
|
|
1410
1413
|
# rdoc-file=numeric.c
|
|
1411
1414
|
# - self - other -> numeric
|
|
1412
1415
|
# -->
|
|
1413
|
-
# Returns the difference of `self` and `other`:
|
|
1416
|
+
# Returns a new Float which is the difference of `self` and `other`:
|
|
1414
1417
|
#
|
|
1415
1418
|
# f = 3.14
|
|
1416
1419
|
# f - 1 # => 2.14
|
|
@@ -1465,9 +1468,10 @@ class Rational
|
|
|
1465
1468
|
|
|
1466
1469
|
# <!--
|
|
1467
1470
|
# rdoc-file=rational.c
|
|
1468
|
-
# -
|
|
1471
|
+
# - rat / numeric -> numeric
|
|
1472
|
+
# - rat.quo(numeric) -> numeric
|
|
1469
1473
|
# -->
|
|
1470
|
-
#
|
|
1474
|
+
# Performs division.
|
|
1471
1475
|
#
|
|
1472
1476
|
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
1473
1477
|
# Rational(900) / Rational(1) #=> (900/1)
|
|
@@ -1480,50 +1484,39 @@ class Rational
|
|
|
1480
1484
|
|
|
1481
1485
|
# <!--
|
|
1482
1486
|
# rdoc-file=rational.c
|
|
1483
|
-
# -
|
|
1487
|
+
# - rat * numeric -> numeric
|
|
1484
1488
|
# -->
|
|
1485
|
-
#
|
|
1489
|
+
# Performs multiplication.
|
|
1486
1490
|
#
|
|
1487
|
-
# Rational(
|
|
1488
|
-
# Rational(
|
|
1489
|
-
# Rational(
|
|
1490
|
-
# Rational(
|
|
1491
|
-
# Rational(
|
|
1492
|
-
# Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
|
1491
|
+
# Rational(2, 3) * Rational(2, 3) #=> (4/9)
|
|
1492
|
+
# Rational(900) * Rational(1) #=> (900/1)
|
|
1493
|
+
# Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
|
1494
|
+
# Rational(9, 8) * 4 #=> (9/2)
|
|
1495
|
+
# Rational(20, 9) * 9.8 #=> 21.77777777777778
|
|
1493
1496
|
#
|
|
1494
1497
|
def *: (BigDecimal) -> BigDecimal
|
|
1495
1498
|
| ...
|
|
1496
1499
|
|
|
1497
1500
|
# <!--
|
|
1498
1501
|
# rdoc-file=rational.c
|
|
1499
|
-
# -
|
|
1502
|
+
# - rat + numeric -> numeric
|
|
1500
1503
|
# -->
|
|
1501
|
-
#
|
|
1502
|
-
#
|
|
1503
|
-
# Rational(2, 3) + 0 # => (2/3)
|
|
1504
|
-
# Rational(2, 3) + 1 # => (5/3)
|
|
1505
|
-
# Rational(2, 3) + -1 # => (-1/3)
|
|
1506
|
-
#
|
|
1507
|
-
# Rational(2, 3) + Complex(1, 0) # => ((5/3)+0i)
|
|
1504
|
+
# Performs addition.
|
|
1508
1505
|
#
|
|
1509
|
-
# Rational(2, 3)
|
|
1510
|
-
# Rational(
|
|
1511
|
-
# Rational(2,
|
|
1512
|
-
# Rational(
|
|
1513
|
-
#
|
|
1514
|
-
# For a computation involving Floats, the result may be inexact (see Float#+):
|
|
1515
|
-
#
|
|
1516
|
-
# Rational(2, 3) + 1.0 # => 1.6666666666666665
|
|
1517
|
-
# Rational(2, 3) + Complex(1.0, 0.0) # => (1.6666666666666665+0.0i)
|
|
1506
|
+
# Rational(2, 3) + Rational(2, 3) #=> (4/3)
|
|
1507
|
+
# Rational(900) + Rational(1) #=> (901/1)
|
|
1508
|
+
# Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
|
|
1509
|
+
# Rational(9, 8) + 4 #=> (41/8)
|
|
1510
|
+
# Rational(20, 9) + 9.8 #=> 12.022222222222222
|
|
1518
1511
|
#
|
|
1519
1512
|
def +: (BigDecimal) -> BigDecimal
|
|
1520
1513
|
| ...
|
|
1521
1514
|
|
|
1522
1515
|
# <!--
|
|
1523
1516
|
# rdoc-file=rational.c
|
|
1524
|
-
# -
|
|
1517
|
+
# - rat - numeric -> numeric
|
|
1525
1518
|
# -->
|
|
1526
|
-
#
|
|
1519
|
+
# Performs subtraction.
|
|
1527
1520
|
#
|
|
1528
1521
|
# Rational(2, 3) - Rational(2, 3) #=> (0/1)
|
|
1529
1522
|
# Rational(900) - Rational(1) #=> (899/1)
|
|
@@ -1560,9 +1553,9 @@ class Complex
|
|
|
1560
1553
|
|
|
1561
1554
|
# <!--
|
|
1562
1555
|
# rdoc-file=complex.c
|
|
1563
|
-
# -
|
|
1556
|
+
# - complex / numeric -> new_complex
|
|
1564
1557
|
# -->
|
|
1565
|
-
# Returns the quotient of `self` and `
|
|
1558
|
+
# Returns the quotient of `self` and `numeric`:
|
|
1566
1559
|
#
|
|
1567
1560
|
# Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
|
|
1568
1561
|
# Complex.rect(900) / Complex.rect(1) # => (900+0i)
|
|
@@ -1575,50 +1568,39 @@ class Complex
|
|
|
1575
1568
|
|
|
1576
1569
|
# <!--
|
|
1577
1570
|
# rdoc-file=complex.c
|
|
1578
|
-
# -
|
|
1571
|
+
# - complex * numeric -> new_complex
|
|
1579
1572
|
# -->
|
|
1580
|
-
# Returns the
|
|
1573
|
+
# Returns the product of `self` and `numeric`:
|
|
1581
1574
|
#
|
|
1582
|
-
# Complex.rect(9, 8) * 4 # => (36+32i)
|
|
1583
|
-
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
1584
1575
|
# Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
|
|
1585
1576
|
# Complex.rect(900) * Complex.rect(1) # => (900+0i)
|
|
1586
1577
|
# Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
|
|
1587
|
-
# Complex.rect(9, 8) *
|
|
1578
|
+
# Complex.rect(9, 8) * 4 # => (36+32i)
|
|
1579
|
+
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
1588
1580
|
#
|
|
1589
1581
|
def *: (BigDecimal) -> Complex
|
|
1590
1582
|
| ...
|
|
1591
1583
|
|
|
1592
1584
|
# <!--
|
|
1593
1585
|
# rdoc-file=complex.c
|
|
1594
|
-
# -
|
|
1586
|
+
# - complex + numeric -> new_complex
|
|
1595
1587
|
# -->
|
|
1596
|
-
# Returns the sum of `self` and `
|
|
1597
|
-
#
|
|
1598
|
-
# Complex(1, 2) + 0 # => (1+2i)
|
|
1599
|
-
# Complex(1, 2) + 1 # => (2+2i)
|
|
1600
|
-
# Complex(1, 2) + -1 # => (0+2i)
|
|
1601
|
-
#
|
|
1602
|
-
# Complex(1, 2) + 1.0 # => (2.0+2i)
|
|
1603
|
-
#
|
|
1604
|
-
# Complex(1, 2) + Complex(2, 1) # => (3+3i)
|
|
1605
|
-
# Complex(1, 2) + Complex(2.0, 1.0) # => (3.0+3.0i)
|
|
1606
|
-
#
|
|
1607
|
-
# Complex(1, 2) + Rational(1, 1) # => ((2/1)+2i)
|
|
1608
|
-
# Complex(1, 2) + Rational(1, 2) # => ((3/2)+2i)
|
|
1609
|
-
#
|
|
1610
|
-
# For a computation involving Floats, the result may be inexact (see Float#+):
|
|
1588
|
+
# Returns the sum of `self` and `numeric`:
|
|
1611
1589
|
#
|
|
1612
|
-
# Complex(
|
|
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)
|
|
1613
1595
|
#
|
|
1614
1596
|
def +: (BigDecimal) -> Complex
|
|
1615
1597
|
| ...
|
|
1616
1598
|
|
|
1617
1599
|
# <!--
|
|
1618
1600
|
# rdoc-file=complex.c
|
|
1619
|
-
# -
|
|
1601
|
+
# - complex - numeric -> new_complex
|
|
1620
1602
|
# -->
|
|
1621
|
-
# Returns the difference of `self` and `
|
|
1603
|
+
# Returns the difference of `self` and `numeric`:
|
|
1622
1604
|
#
|
|
1623
1605
|
# Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
|
|
1624
1606
|
# Complex.rect(900) - Complex.rect(1) # => (899+0i)
|