rbs 3.10.0.pre.1 → 3.10.0
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/c-check.yml +1 -1
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/ruby.yml +7 -7
- data/CHANGELOG.md +49 -0
- data/core/array.rbs +56 -3
- data/core/complex.rbs +32 -21
- data/core/encoding.rbs +3 -7
- data/core/enumerable.rbs +1 -1
- data/core/enumerator.rbs +18 -1
- data/core/fiber.rbs +2 -1
- data/core/file.rbs +1 -1
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +208 -21
- data/core/gc.rbs +4 -9
- data/core/hash.rbs +4 -4
- data/core/integer.rbs +78 -38
- data/core/io/buffer.rbs +18 -7
- data/core/io.rbs +8 -8
- data/core/kernel.rbs +8 -8
- data/core/module.rbs +17 -6
- data/core/numeric.rbs +8 -8
- data/core/object_space.rbs +13 -20
- data/core/pathname.rbs +2 -3
- data/core/ractor.rbs +4 -4
- data/core/range.rbs +1 -1
- data/core/rational.rbs +37 -24
- data/core/rbs/unnamed/argf.rbs +1 -1
- data/core/regexp.rbs +3 -3
- data/core/ruby.rbs +53 -0
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +86 -64
- data/core/string.rbs +275 -141
- data/core/thread.rbs +9 -9
- data/core/trace_point.rbs +7 -4
- data/docs/encoding.md +56 -0
- data/ext/rbs_extension/class_constants.c +0 -2
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +1 -9
- data/include/rbs/parser.h +2 -2
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/lib/rbs/test/type_check.rb +1 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/src/location.c +1 -1
- data/src/parser.c +59 -47
- data/src/string.c +0 -49
- data/src/util/rbs_allocator.c +2 -2
- data/src/util/rbs_assert.c +0 -2
- data/src/util/rbs_constant_pool.c +4 -4
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/json/0/json.rbs +1 -0
- data/stdlib/objspace/0/objspace.rbs +1 -1
- data/stdlib/openssl/0/openssl.rbs +150 -80
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/stringio/0/stringio.rbs +796 -37
- data/stdlib/strscan/0/string_scanner.rbs +1 -1
- data/stdlib/tempfile/0/tempfile.rbs +2 -2
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/uri/0/generic.rbs +1 -1
- metadata +4 -2
data/src/string.c
CHANGED
|
@@ -1,59 +1,10 @@
|
|
|
1
1
|
#include "rbs/string.h"
|
|
2
|
-
#include "rbs/defines.h"
|
|
3
2
|
|
|
4
3
|
#include <stdlib.h>
|
|
5
4
|
#include <string.h>
|
|
6
5
|
#include <stdio.h>
|
|
7
6
|
#include <ctype.h>
|
|
8
7
|
|
|
9
|
-
unsigned int rbs_utf8_string_to_codepoint(const rbs_string_t string) {
|
|
10
|
-
unsigned int codepoint = 0;
|
|
11
|
-
int remaining_bytes = 0;
|
|
12
|
-
|
|
13
|
-
const char *s = string.start;
|
|
14
|
-
const char *end = string.end;
|
|
15
|
-
|
|
16
|
-
if (s >= end) return 0; // End of string
|
|
17
|
-
|
|
18
|
-
if (RBS_LIKELY((*s & 0x80) == 0)) {
|
|
19
|
-
// Single byte character (0xxxxxxx)
|
|
20
|
-
return *s;
|
|
21
|
-
} else if ((*s & 0xE0) == 0xC0) {
|
|
22
|
-
// Two byte character (110xxxxx 10xxxxxx)
|
|
23
|
-
codepoint = *s & 0x1F;
|
|
24
|
-
remaining_bytes = 1;
|
|
25
|
-
} else if ((*s & 0xF0) == 0xE0) {
|
|
26
|
-
// Three byte character (1110xxxx 10xxxxxx 10xxxxxx)
|
|
27
|
-
codepoint = *s & 0x0F;
|
|
28
|
-
remaining_bytes = 2;
|
|
29
|
-
} else if ((*s & 0xF8) == 0xF0) {
|
|
30
|
-
// Four byte character (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
|
|
31
|
-
codepoint = *s & 0x07;
|
|
32
|
-
remaining_bytes = 3;
|
|
33
|
-
} else {
|
|
34
|
-
// Invalid UTF-8 sequence
|
|
35
|
-
return 0xFFFD; // Unicode replacement character
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
s++;
|
|
39
|
-
while (remaining_bytes > 0 && s < end) {
|
|
40
|
-
if ((*s & 0xC0) != 0x80) {
|
|
41
|
-
// Invalid continuation byte
|
|
42
|
-
return 0xFFFD;
|
|
43
|
-
}
|
|
44
|
-
codepoint = (codepoint << 6) | (*s & 0x3F);
|
|
45
|
-
s++;
|
|
46
|
-
remaining_bytes--;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (remaining_bytes > 0) {
|
|
50
|
-
// Incomplete sequence
|
|
51
|
-
return 0xFFFD;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return codepoint;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
8
|
rbs_string_t rbs_string_new(const char *start, const char *end) {
|
|
58
9
|
return (rbs_string_t) {
|
|
59
10
|
.start = start,
|
data/src/util/rbs_allocator.c
CHANGED
|
@@ -57,7 +57,7 @@ static size_t get_system_page_size(void) {
|
|
|
57
57
|
static rbs_allocator_page_t *rbs_allocator_page_new(size_t payload_size) {
|
|
58
58
|
const size_t page_header_size = sizeof(rbs_allocator_page_t);
|
|
59
59
|
|
|
60
|
-
rbs_allocator_page_t *page = malloc(page_header_size + payload_size);
|
|
60
|
+
rbs_allocator_page_t *page = (rbs_allocator_page_t *) malloc(page_header_size + payload_size);
|
|
61
61
|
page->size = payload_size;
|
|
62
62
|
page->used = 0;
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ static rbs_allocator_page_t *rbs_allocator_page_new(size_t payload_size) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
rbs_allocator_t *rbs_allocator_init(void) {
|
|
68
|
-
rbs_allocator_t *allocator = malloc(sizeof(rbs_allocator_t));
|
|
68
|
+
rbs_allocator_t *allocator = (rbs_allocator_t *) malloc(sizeof(rbs_allocator_t));
|
|
69
69
|
|
|
70
70
|
const size_t system_page_size = get_system_page_size();
|
|
71
71
|
|
data/src/util/rbs_assert.c
CHANGED
|
@@ -57,8 +57,8 @@ rbs_constant_pool_resize(rbs_constant_pool_t *pool) {
|
|
|
57
57
|
void *next = calloc(next_capacity, element_size);
|
|
58
58
|
if (next == NULL) return false;
|
|
59
59
|
|
|
60
|
-
rbs_constant_pool_bucket_t *next_buckets = next;
|
|
61
|
-
rbs_constant_t *next_constants = (
|
|
60
|
+
rbs_constant_pool_bucket_t *next_buckets = (rbs_constant_pool_bucket_t *) next;
|
|
61
|
+
rbs_constant_t *next_constants = (rbs_constant_t *) (((char *) next) + next_capacity * sizeof(rbs_constant_pool_bucket_t));
|
|
62
62
|
|
|
63
63
|
// For each bucket in the current constant pool, find the index in the
|
|
64
64
|
// next constant pool, and insert it.
|
|
@@ -111,8 +111,8 @@ bool rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity) {
|
|
|
111
111
|
void *memory = calloc(capacity, element_size);
|
|
112
112
|
if (memory == NULL) return false;
|
|
113
113
|
|
|
114
|
-
pool->buckets = memory;
|
|
115
|
-
pool->constants = (
|
|
114
|
+
pool->buckets = (rbs_constant_pool_bucket_t *) memory;
|
|
115
|
+
pool->constants = (rbs_constant_t *) (((char *) memory) + capacity * sizeof(rbs_constant_pool_bucket_t));
|
|
116
116
|
pool->size = 0;
|
|
117
117
|
pool->capacity = capacity;
|
|
118
118
|
return true;
|
data/src/util/rbs_unescape.c
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include "rbs/util/rbs_unescape.h"
|
|
2
|
+
#include "rbs/util/rbs_encoding.h"
|
|
2
3
|
#include <string.h>
|
|
3
4
|
#include <stdlib.h>
|
|
4
5
|
#include <ctype.h>
|
|
@@ -42,20 +43,44 @@ static int octal_to_int(const char *octal, int length) {
|
|
|
42
43
|
return result;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
46
|
+
// Fills buf starting at index 'start' with the UTF-8 encoding of 'codepoint'.
|
|
47
|
+
// Returns the number of bytes written, or 0 when the output is not changed.
|
|
48
|
+
//
|
|
49
|
+
size_t rbs_utf8_fill_codepoint(char *buf, size_t start, size_t end, unsigned int codepoint) {
|
|
50
|
+
if (start + 4 > end) {
|
|
51
|
+
return 0;
|
|
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
|
+
}
|
|
51
75
|
}
|
|
52
76
|
|
|
53
|
-
rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t string, bool is_double_quote) {
|
|
77
|
+
rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t string, bool is_double_quote, bool is_unicode) {
|
|
54
78
|
if (!string.start) return RBS_STRING_NULL;
|
|
55
79
|
|
|
56
80
|
size_t len = string.end - string.start;
|
|
57
81
|
const char *input = string.start;
|
|
58
82
|
|
|
83
|
+
// The output cannot be longer than the input even after unescaping.
|
|
59
84
|
char *output = rbs_allocator_alloc_many(allocator, len + 1, char);
|
|
60
85
|
if (!output) return RBS_STRING_NULL;
|
|
61
86
|
|
|
@@ -79,9 +104,21 @@ rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t stri
|
|
|
79
104
|
i += hex_len + 2;
|
|
80
105
|
} else if (input[i + 1] == 'u' && i + 5 < len) {
|
|
81
106
|
// Unicode escape
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
|
|
108
|
+
if (is_unicode) {
|
|
109
|
+
// The UTF-8 representation is at most 4 bytes, shorter than the input length.
|
|
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
|
+
}
|
|
85
122
|
} else {
|
|
86
123
|
// Other escapes
|
|
87
124
|
int found = 0;
|
|
@@ -114,18 +151,17 @@ rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t stri
|
|
|
114
151
|
return rbs_string_new(output, output + j);
|
|
115
152
|
}
|
|
116
153
|
|
|
117
|
-
rbs_string_t rbs_unquote_string(rbs_allocator_t *allocator, rbs_string_t input) {
|
|
118
|
-
unsigned int first_char =
|
|
119
|
-
|
|
154
|
+
rbs_string_t rbs_unquote_string(rbs_allocator_t *allocator, rbs_string_t input, const rbs_encoding_t *encoding) {
|
|
155
|
+
unsigned int first_char = input.start[0];
|
|
156
|
+
|
|
157
|
+
const char *new_start = input.start;
|
|
158
|
+
const char *new_end = input.end;
|
|
120
159
|
|
|
121
|
-
ptrdiff_t start_offset = 0;
|
|
122
160
|
if (first_char == '"' || first_char == '\'' || first_char == '`') {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
byte_length -= 2 * bs;
|
|
161
|
+
new_start += 1;
|
|
162
|
+
new_end -= 1;
|
|
126
163
|
}
|
|
127
164
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return unescape_string(allocator, string, first_char == '"');
|
|
165
|
+
rbs_string_t string = rbs_string_new(new_start, new_end);
|
|
166
|
+
return unescape_string(allocator, string, first_char == '"', encoding == RBS_ENCODING_UTF_8_ENTRY);
|
|
131
167
|
}
|
|
@@ -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) -> [ Integer, BigDecimal ]
|
|
613
613
|
|
|
614
614
|
# <!--
|
|
615
615
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
@@ -783,20 +783,6 @@ 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
|
-
|
|
800
786
|
# <!--
|
|
801
787
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
|
802
788
|
# - quo(value) -> bigdecimal
|
|
@@ -1274,33 +1260,35 @@ class Integer
|
|
|
1274
1260
|
|
|
1275
1261
|
# <!--
|
|
1276
1262
|
# rdoc-file=numeric.c
|
|
1277
|
-
# - self /
|
|
1263
|
+
# - self / other -> numeric
|
|
1278
1264
|
# -->
|
|
1279
|
-
#
|
|
1265
|
+
# Returns the quotient of `self` and `other`.
|
|
1266
|
+
#
|
|
1267
|
+
# For integer `other`, truncates the result to an integer:
|
|
1280
1268
|
#
|
|
1281
|
-
#
|
|
1282
|
-
#
|
|
1283
|
-
#
|
|
1284
|
-
#
|
|
1269
|
+
# 4 / 3 # => 1
|
|
1270
|
+
# 4 / -3 # => -2
|
|
1271
|
+
# -4 / 3 # => -2
|
|
1272
|
+
# -4 / -3 # => 1
|
|
1285
1273
|
#
|
|
1286
|
-
#
|
|
1274
|
+
# For non-integer `other`, returns a non-integer result:
|
|
1287
1275
|
#
|
|
1288
|
-
#
|
|
1289
|
-
#
|
|
1290
|
-
#
|
|
1276
|
+
# 4 / 3.0 # => 1.3333333333333333
|
|
1277
|
+
# 4 / Rational(3, 1) # => (4/3)
|
|
1278
|
+
# 4 / Complex(3, 0) # => ((4/3)+0i)
|
|
1291
1279
|
#
|
|
1292
1280
|
def /: (BigDecimal) -> BigDecimal
|
|
1293
1281
|
| ...
|
|
1294
1282
|
|
|
1295
1283
|
# <!--
|
|
1296
1284
|
# rdoc-file=numeric.c
|
|
1297
|
-
# - self *
|
|
1285
|
+
# - self * other -> numeric
|
|
1298
1286
|
# -->
|
|
1299
|
-
#
|
|
1287
|
+
# Returns the numeric product of `self` and `other`:
|
|
1300
1288
|
#
|
|
1301
1289
|
# 4 * 2 # => 8
|
|
1302
|
-
# 4 * -2 # => -8
|
|
1303
1290
|
# -4 * 2 # => -8
|
|
1291
|
+
# 4 * -2 # => -8
|
|
1304
1292
|
# 4 * 2.0 # => 8.0
|
|
1305
1293
|
# 4 * Rational(1, 3) # => (4/3)
|
|
1306
1294
|
# 4 * Complex(2, 0) # => (8+0i)
|
|
@@ -1310,25 +1298,29 @@ class Integer
|
|
|
1310
1298
|
|
|
1311
1299
|
# <!--
|
|
1312
1300
|
# rdoc-file=numeric.c
|
|
1313
|
-
# - self +
|
|
1301
|
+
# - self + other -> numeric
|
|
1314
1302
|
# -->
|
|
1315
|
-
#
|
|
1303
|
+
# Returns the sum of `self` and `other`:
|
|
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)
|
|
1316
1311
|
#
|
|
1317
|
-
#
|
|
1318
|
-
#
|
|
1319
|
-
#
|
|
1320
|
-
# 2 + 2.0 # => 4.0
|
|
1321
|
-
# 2 + Rational(2, 1) # => (4/1)
|
|
1322
|
-
# 2 + Complex(2, 0) # => (4+0i)
|
|
1312
|
+
# For a computation involving Floats, the result may be inexact (see Float#+):
|
|
1313
|
+
#
|
|
1314
|
+
# 1 + 3.14 # => 4.140000000000001
|
|
1323
1315
|
#
|
|
1324
1316
|
def +: (BigDecimal) -> BigDecimal
|
|
1325
1317
|
| ...
|
|
1326
1318
|
|
|
1327
1319
|
# <!--
|
|
1328
1320
|
# rdoc-file=numeric.c
|
|
1329
|
-
# - self -
|
|
1321
|
+
# - self - other -> numeric
|
|
1330
1322
|
# -->
|
|
1331
|
-
#
|
|
1323
|
+
# Returns the difference of `self` and `other`:
|
|
1332
1324
|
#
|
|
1333
1325
|
# 4 - 2 # => 2
|
|
1334
1326
|
# -4 - 2 # => -6
|
|
@@ -1368,7 +1360,7 @@ class Float
|
|
|
1368
1360
|
# rdoc-file=numeric.c
|
|
1369
1361
|
# - self / other -> numeric
|
|
1370
1362
|
# -->
|
|
1371
|
-
# Returns
|
|
1363
|
+
# Returns the quotient of `self` and `other`:
|
|
1372
1364
|
#
|
|
1373
1365
|
# f = 3.14
|
|
1374
1366
|
# f / 2 # => 1.57
|
|
@@ -1383,7 +1375,7 @@ class Float
|
|
|
1383
1375
|
# rdoc-file=numeric.c
|
|
1384
1376
|
# - self * other -> numeric
|
|
1385
1377
|
# -->
|
|
1386
|
-
# Returns
|
|
1378
|
+
# Returns the numeric product of `self` and `other`:
|
|
1387
1379
|
#
|
|
1388
1380
|
# f = 3.14
|
|
1389
1381
|
# f * 2 # => 6.28
|
|
@@ -1396,15 +1388,20 @@ class Float
|
|
|
1396
1388
|
|
|
1397
1389
|
# <!--
|
|
1398
1390
|
# rdoc-file=numeric.c
|
|
1399
|
-
# - self + other ->
|
|
1391
|
+
# - self + other -> float or complex
|
|
1400
1392
|
# -->
|
|
1401
|
-
# Returns
|
|
1393
|
+
# Returns the sum of `self` and `other`; the result may be inexact (see Float):
|
|
1402
1394
|
#
|
|
1403
|
-
#
|
|
1404
|
-
#
|
|
1405
|
-
#
|
|
1406
|
-
#
|
|
1407
|
-
#
|
|
1395
|
+
# 3.14 + 0 # => 3.14
|
|
1396
|
+
# 3.14 + 1 # => 4.140000000000001
|
|
1397
|
+
# -3.14 + 0 # => -3.14
|
|
1398
|
+
# -3.14 + 1 # => -2.14
|
|
1399
|
+
#
|
|
1400
|
+
# 3.14 + -3.14 # => 0.0
|
|
1401
|
+
# -3.14 + -3.14 # => -6.28
|
|
1402
|
+
#
|
|
1403
|
+
# 3.14 + Complex(1, 0) # => (4.140000000000001+0i)
|
|
1404
|
+
# 3.14 + Rational(1, 1) # => 4.140000000000001
|
|
1408
1405
|
#
|
|
1409
1406
|
def +: (BigDecimal) -> BigDecimal
|
|
1410
1407
|
| ...
|
|
@@ -1413,7 +1410,7 @@ class Float
|
|
|
1413
1410
|
# rdoc-file=numeric.c
|
|
1414
1411
|
# - self - other -> numeric
|
|
1415
1412
|
# -->
|
|
1416
|
-
# Returns
|
|
1413
|
+
# Returns the difference of `self` and `other`:
|
|
1417
1414
|
#
|
|
1418
1415
|
# f = 3.14
|
|
1419
1416
|
# f - 1 # => 2.14
|
|
@@ -1468,10 +1465,9 @@ class Rational
|
|
|
1468
1465
|
|
|
1469
1466
|
# <!--
|
|
1470
1467
|
# rdoc-file=rational.c
|
|
1471
|
-
# -
|
|
1472
|
-
# - rat.quo(numeric) -> numeric
|
|
1468
|
+
# - self / other -> numeric
|
|
1473
1469
|
# -->
|
|
1474
|
-
#
|
|
1470
|
+
# Returns the quotient of `self` and `other`:
|
|
1475
1471
|
#
|
|
1476
1472
|
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
1477
1473
|
# Rational(900) / Rational(1) #=> (900/1)
|
|
@@ -1484,39 +1480,50 @@ class Rational
|
|
|
1484
1480
|
|
|
1485
1481
|
# <!--
|
|
1486
1482
|
# rdoc-file=rational.c
|
|
1487
|
-
# -
|
|
1483
|
+
# - self * other -> numeric
|
|
1488
1484
|
# -->
|
|
1489
|
-
#
|
|
1485
|
+
# Returns the numeric product of `self` and `other`:
|
|
1490
1486
|
#
|
|
1491
|
-
# Rational(
|
|
1492
|
-
# Rational(
|
|
1493
|
-
# Rational(
|
|
1494
|
-
# Rational(
|
|
1495
|
-
# Rational(
|
|
1487
|
+
# Rational(9, 8) * 4 #=> (9/2)
|
|
1488
|
+
# Rational(20, 9) * 9.8 #=> 21.77777777777778
|
|
1489
|
+
# Rational(9, 8) * Complex(1, 2) # => ((9/8)+(9/4)*i)
|
|
1490
|
+
# Rational(2, 3) * Rational(2, 3) #=> (4/9)
|
|
1491
|
+
# Rational(900) * Rational(1) #=> (900/1)
|
|
1492
|
+
# Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
|
1496
1493
|
#
|
|
1497
1494
|
def *: (BigDecimal) -> BigDecimal
|
|
1498
1495
|
| ...
|
|
1499
1496
|
|
|
1500
1497
|
# <!--
|
|
1501
1498
|
# rdoc-file=rational.c
|
|
1502
|
-
# -
|
|
1499
|
+
# - self + other -> numeric
|
|
1503
1500
|
# -->
|
|
1504
|
-
#
|
|
1501
|
+
# Returns the sum of `self` and `other`:
|
|
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)
|
|
1505
1508
|
#
|
|
1506
|
-
# Rational(2, 3)
|
|
1507
|
-
# Rational(
|
|
1508
|
-
# Rational(
|
|
1509
|
-
# Rational(
|
|
1510
|
-
#
|
|
1509
|
+
# Rational(2, 3) + Rational(1, 1) # => (5/3)
|
|
1510
|
+
# Rational(2, 3) + Rational(3, 2) # => (13/6)
|
|
1511
|
+
# Rational(2, 3) + Rational(3.0, 2.0) # => (13/6)
|
|
1512
|
+
# Rational(2, 3) + Rational(3.1, 2.1) # => (30399297484750849/14186338826217063)
|
|
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)
|
|
1511
1518
|
#
|
|
1512
1519
|
def +: (BigDecimal) -> BigDecimal
|
|
1513
1520
|
| ...
|
|
1514
1521
|
|
|
1515
1522
|
# <!--
|
|
1516
1523
|
# rdoc-file=rational.c
|
|
1517
|
-
# -
|
|
1524
|
+
# - self - other -> numeric
|
|
1518
1525
|
# -->
|
|
1519
|
-
#
|
|
1526
|
+
# Returns the difference of `self` and `other`:
|
|
1520
1527
|
#
|
|
1521
1528
|
# Rational(2, 3) - Rational(2, 3) #=> (0/1)
|
|
1522
1529
|
# Rational(900) - Rational(1) #=> (899/1)
|
|
@@ -1553,9 +1560,9 @@ class Complex
|
|
|
1553
1560
|
|
|
1554
1561
|
# <!--
|
|
1555
1562
|
# rdoc-file=complex.c
|
|
1556
|
-
# -
|
|
1563
|
+
# - self / other -> complex
|
|
1557
1564
|
# -->
|
|
1558
|
-
# Returns the quotient of `self` and `
|
|
1565
|
+
# Returns the quotient of `self` and `other`:
|
|
1559
1566
|
#
|
|
1560
1567
|
# Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
|
|
1561
1568
|
# Complex.rect(900) / Complex.rect(1) # => (900+0i)
|
|
@@ -1568,39 +1575,50 @@ class Complex
|
|
|
1568
1575
|
|
|
1569
1576
|
# <!--
|
|
1570
1577
|
# rdoc-file=complex.c
|
|
1571
|
-
# -
|
|
1578
|
+
# - self * other -> numeric
|
|
1572
1579
|
# -->
|
|
1573
|
-
# Returns the product of `self` and `
|
|
1580
|
+
# Returns the numeric product of `self` and `other`:
|
|
1574
1581
|
#
|
|
1582
|
+
# Complex.rect(9, 8) * 4 # => (36+32i)
|
|
1583
|
+
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
1575
1584
|
# Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
|
|
1576
1585
|
# Complex.rect(900) * Complex.rect(1) # => (900+0i)
|
|
1577
1586
|
# Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
|
|
1578
|
-
# Complex.rect(9, 8) *
|
|
1579
|
-
# Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
|
|
1587
|
+
# Complex.rect(9, 8) * Rational(2, 3) # => ((6/1)+(16/3)*i)
|
|
1580
1588
|
#
|
|
1581
1589
|
def *: (BigDecimal) -> Complex
|
|
1582
1590
|
| ...
|
|
1583
1591
|
|
|
1584
1592
|
# <!--
|
|
1585
1593
|
# rdoc-file=complex.c
|
|
1586
|
-
# -
|
|
1594
|
+
# - self + other -> numeric
|
|
1587
1595
|
# -->
|
|
1588
|
-
# Returns the sum of `self` and `
|
|
1596
|
+
# Returns the sum of `self` and `other`:
|
|
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#+):
|
|
1589
1611
|
#
|
|
1590
|
-
# Complex
|
|
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)
|
|
1612
|
+
# Complex(1, 2) + 3.14 # => (4.140000000000001+2i)
|
|
1595
1613
|
#
|
|
1596
1614
|
def +: (BigDecimal) -> Complex
|
|
1597
1615
|
| ...
|
|
1598
1616
|
|
|
1599
1617
|
# <!--
|
|
1600
1618
|
# rdoc-file=complex.c
|
|
1601
|
-
# -
|
|
1619
|
+
# - self - other -> complex
|
|
1602
1620
|
# -->
|
|
1603
|
-
# Returns the difference of `self` and `
|
|
1621
|
+
# Returns the difference of `self` and `other`:
|
|
1604
1622
|
#
|
|
1605
1623
|
# Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
|
|
1606
1624
|
# Complex.rect(900) - Complex.rect(1) # => (899+0i)
|