dearblue
8ecfacefca
Prohibit Class#allocate in a different way
...
The method introduced by #5979 causes a fault by swapping classes.
```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
zsh: segmentation fault (core dumped) bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
```
After applying this patch, a `TypeError` exception will be raised.
```console
% bin/mruby -e 'Method = Proc; p Object.method(:inspect)'
trace (most recent call last):
[1] -e:1
-e:1:in method: allocation failure of Proc (TypeError)
```
However, if the `mrb_vtype` is the same object, the same care must still be taken as before.
```console
% bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")'
trace (most recent call last):
[1] -e:1
-e:1:in eval: wrong argument type nil (expected Proc) (TypeError)
```
2023-12-22 21:59:34 +09:00
Yukihiro "Matz" Matsumoto
df1d397da5
numeric.c: use presym to initialize numeric classes
2023-11-11 23:48:31 +09:00
Yukihiro "Matz" Matsumoto
0443f14fd0
array.c,hash.c,numeric.c,string.c: use mrb_define_method_id()
...
For primary class libraries.
2023-10-23 15:23:08 +09:00
Yukihiro "Matz" Matsumoto
3277cc9ce1
numeric.c (int_to_s): avoid mrb_get_args()
2023-10-11 20:32:09 +09:00
Yukihiro "Matz" Matsumoto
5d0016186f
numeric.c (mrb_float_to_str): avoid memcpy()
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
89f7bb1056
use more lightweight mrb_funcall_argv instead of mrb_funcall_id
2023-06-12 14:22:04 +09:00
Yukihiro "Matz" Matsumoto
6eedf1065d
numeric.c (flo_idiv): add mrb_check_num_exact
2023-05-30 08:54:44 +09:00
Yukihiro "Matz" Matsumoto
f1a3cfbd3b
add a space between if and (
2023-05-22 11:55:21 +09:00
Yukihiro "Matz" Matsumoto
c32f7915fb
reformat else clause indentation style
2023-05-20 00:21:01 +09:00
dearblue
0279067dc4
Returns the value of Integer#~ from mrb_bint_rev()
...
fixed #5987
2023-04-15 22:39:05 +09:00
dearblue
d3128ce58a
Allow Class#allocate to be prohibited
...
Calling `Class#allocate` with `UnboundMethod#bind_call` usually succeeds without problems.
If this behavior does not make us happy, we can now prohibit it with `MRB_SET_INSTANCE_TT(klass, MRB_TT_UNDEF)`.
At the same time, it applies to the `Binding`, `Complex`, `Data`, `Float`, `Integer`, `Method`, `Rational` and `UnboundMethod` classes.
2023-04-09 21:14:07 +09:00
Yukihiro "Matz" Matsumoto
0906cd7593
numeric.c: fix rounding function issues with big numbers
...
- int_ceil
- int_floor
- int_round
- int_truncate
2023-03-13 18:53:17 +09:00
Yukihiro "Matz" Matsumoto
ea0e8f7ea4
numeric.c (flo_mod): use NULL instead of 0
...
In C, we don't use 0 as NULL representation.
2023-02-13 00:08:40 +09:00
Yukihiro "Matz" Matsumoto
4e85e855cf
numeric.c: avoid mrb_get_args() if possible
2023-01-25 14:10:43 +09:00
Yukihiro "Matz" Matsumoto
37da677cc8
numeric.c (mrb_int_pow): avoid unnecessary calls to mrb_get_args()
2023-01-24 15:25:06 +09:00
Yukihiro "Matz" Matsumoto
89830296eb
numeric.c (int_round): n may not be a bigint
...
`mrb_bint_add()` expects its first operand to be a bigint.
2022-12-24 19:20:37 +09:00
John Bampton
8208a836ff
Fix spelling: floating point -> floating-point
...
https://en.wikipedia.org/wiki/Floating-point_arithmetic
2022-10-27 00:09:12 +10:00
Yukihiro "Matz" Matsumoto
268f6dcab3
numeric.c (mrb_float_to_integer): isinf/isnan takes any float values.
...
So don't need to cast to `float`, just use `mrb_float`.
2022-10-04 11:05:15 +09:00
Yukihiro "Matz" Matsumoto
d9061bd969
numeric.c: update documents [ci skip].
2022-09-23 22:13:28 +09:00
Yukihiro "Matz" Matsumoto
b891c63ae1
numeric.c: calculate correct rounding for bigger numbers.
2022-08-12 12:31:38 +09:00
Yukihiro "Matz" Matsumoto
1a95da4ac2
numeric.c (mrb_cmp): inline big-integer comparison.
2022-08-12 12:24:04 +09:00
Yukihiro "Matz" Matsumoto
d14fd77148
numeric.c (mrb_int_pow): make the function to take 2 operands.
2022-08-12 12:19:21 +09:00
Yukihiro "Matz" Matsumoto
8cdf14c06b
numeric.c (int_rounding): unify code duplication.
2022-08-10 13:38:24 +09:00
Yukihiro "Matz" Matsumoto
4e735eb8ba
numeric.c (flo_rounding): refactor float rounding methods.
2022-08-10 13:38:24 +09:00
Yukihiro "Matz" Matsumoto
7ffdb4c30e
numeric.c: implement ndigits truncation for rounding methods.
...
- ceil
- floor
- round
- truncate
2022-08-10 13:38:23 +09:00
Yukihiro "Matz" Matsumoto
abec98c681
numeric.c: implement ceil, floor, round, truncate methods in C.
...
- ISO 15.2.8.3.14 Integer#ceil
- ISO 15.2.8.3.17 Integer#floor
- ISO 15.2.8.3.20 Integer#round
- ISO 15.2.8.3.26 Integer#truncate
2022-08-10 13:38:23 +09:00
Yukihiro "Matz" Matsumoto
78a3200fa5
etc.c (mrb_obj_id): separate object_id and hash values.
...
It's OK for hash values to conflict. But object_id is not (in theory).
2022-08-08 23:00:13 +09:00
Yukihiro "Matz" Matsumoto
585d80e0a7
numeric.c (num_eql): move eql? definition to Numeric class.
...
We no longer need Float#eql? etc.
2022-08-01 16:20:35 +09:00
Yukihiro "Matz" Matsumoto
b77b8f4deb
numeric.c (flo_ceil_floor): negate after converting integer to float.
...
Otherwise integer negate may overflow.
2022-07-30 09:08:42 +09:00
Yukihiro "Matz" Matsumoto
9d774bc011
numeric.c (flo_ceil_floor): return bigint if possible.
2022-07-30 09:08:02 +09:00
Yukihiro "Matz" Matsumoto
eb392cb643
numeric.c (mrb_float_to_integer): check for RangeError.
...
Otherwise flo_to_i raises FloatDomainError instead.
2022-07-30 09:06:49 +09:00
Yukihiro "Matz" Matsumoto
e4bcd8a96a
numeric.c (mrb_float_to_integer): unify with flo_to_i().
2022-07-30 09:05:21 +09:00
Yukihiro "Matz" Matsumoto
5af98f2088
numeric.c (flo_ceil_floor): add exact number check.
2022-07-30 09:01:24 +09:00
Yukihiro "Matz" Matsumoto
b8d3bc0eae
numeric.c: move FloatDomainError description to the sufficient place.
2022-07-30 08:46:06 +09:00
Yukihiro "Matz" Matsumoto
6da34fa735
numeric.c (int_div): add checks for division by zero.
2022-07-29 17:48:02 +09:00
Yukihiro "Matz" Matsumoto
0e530dbb63
numeric.c: fix smallint op bigint error in bitwise logical operators.
2022-07-18 08:29:52 +09:00
Yukihiro "Matz" Matsumoto
37c2f080f0
numeric.c (int_to_s): should not bypass base range check.
2022-07-12 14:48:36 +09:00
Yukihiro "Matz" Matsumoto
48b43af37f
numeric.c (mrb_div_int_value): should support integer overflow.
...
Especially in `MRB_INT_MIN/-1` which is bigger than MRB_INT_MAX.
2022-07-09 15:21:45 +09:00
Yukihiro "Matz" Matsumoto
fa0ff7cf86
numeric.c: better error message (Float -> Integer).
2022-07-09 15:13:52 +09:00
Yukihiro "Matz" Matsumoto
7de03cbb68
numeric.c: add mrb_noreturn qualifier to error functions.
...
- mrb_int_zerodiv()
- mrb_int_overflow()
2022-07-09 15:12:37 +09:00
Yukihiro "Matz" Matsumoto
e1980d7596
numeric.c (mrb_div_int): separate the function in two.
...
- mrb_div_int() does integer division in Ruby way (mdiv)
returns mrb_int
- mrb_div_int_value() division with zero div and overflow checks.
returns mrb_value
2022-07-09 14:38:18 +09:00
Yukihiro "Matz" Matsumoto
a2f0fd81e6
numeric.c (mrb_int_mul): fix error message (Float -> Integer).
2022-07-09 10:45:44 +09:00
Yukihiro "Matz" Matsumoto
8d34981530
numeric.c: avoid mathematical operations for simple cases.
2022-07-09 10:45:11 +09:00
Yukihiro "Matz" Matsumoto
960021e519
numeric.c (cmpnum): call mrb_bigint_cmp() if v1 is bigint, not v2.
2022-07-08 21:57:05 +09:00
Yukihiro "Matz" Matsumoto
39c8c051f8
numeric.c: mrb_integer_to_str now supports big integers.
2022-04-25 10:03:47 +09:00
Yukihiro "Matz" Matsumoto
df09838503
numeric.c: mrb_float_to_integer can return a big integer.
2022-04-25 10:02:54 +09:00
Yukihiro "Matz" Matsumoto
0f4769536b
src/numeric.c: use mrb_ensure_float_type().
...
Instead of obsolete `mrb_to_float()` or the combination of
`mrb_float_value(mrb_as_float())`.
2022-04-25 07:29:55 +09:00
Yukihiro "Matz" Matsumoto
56a35131a4
numeric.c (mrb_cmp): should not raise NoMethodError.
...
Even when `obj1` does not have `<=>` method.
2022-04-24 14:02:00 +09:00
Yukihiro "Matz" Matsumoto
9dd45df804
numeric.c (int_pow): should not overflow.
2022-04-21 11:35:52 +09:00
Yukihiro "Matz" Matsumoto
b38a766427
numeric.c (flo_to_i): use bigint if the value is bigger than mrb_int.
2022-04-18 12:31:15 +09:00