summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
AgeCommit message (Collapse)Author
2020-10-12Extract `div` code in VM and make them shared by `div` methods.Yukihiro "Matz" Matsumoto
2020-10-12Remove obsolete `MRB_WITHOUT_FLOAT` macro from `numeric.c`.Yukihiro "Matz" Matsumoto
2020-10-12Stop warning on 64 bit platforms.Yukihiro "Matz" Matsumoto
2020-10-12Handle potential overflow in `int_div` and `flo_idiv`.Yukihiro "Matz" Matsumoto
2020-10-12Use `mrb_int_value()` instead of `mrb_fixnum_value()`.Yukihiro "Matz" Matsumoto
Where fixnum overflow can happen.
2020-10-12Reorganize `Integer` system.Yukihiro "Matz" Matsumoto
- Integrate `Fixnum` and `Integer` - Remove `Integral` - `int / int -> int` - Replace `mrb_fixnum()` to `mrb_int()` - Replace `mrb_fixnum_value()` to `mrb_int_value()`. - Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12Make division by zero cause `ZeroDivisionError`.Yukihiro "Matz" Matsumoto
As described in ISO 15.2.30.
2020-10-12Rename `MRB_TT_FIXNUM` to `MRB_TT_INTEGER`.Yukihiro "Matz" Matsumoto
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12Always add trailing `.0` in `Float#inspect`; ref #4225KOBAYASHI Shuji
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at 9d08025b. However, I think the more human-readable format is better for `Float#inspect`. For example, in the `Float#to_s` format, the failure message is not well understood when testing values including types by `eql?` (e.g. `Numeric#step` test). ```ruby assert "example" do exp = 1.0 act = 1 assert_operator(exp, :eql?, act) #=> Expected 1 to be eql? 1. end ```
2020-10-12Integrate `Fixnum` class into `Integer` classdearblue
* The `Fixnum` constant is now an alias for the `Integer` class. * Remove `struct mrb_state::fixnum_class` member. If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12Rename float configuration option names.Yukihiro "Matz" Matsumoto
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT` - `MRB_USE_FLOAT` => `MRB_USE_FLOAT32` The former is to use `USE_XXX` naming convention. The latter is to make sure `float` is 32bit float and not floating point number in general.
2020-10-12Use functions that take symbols to reduce string litrals in C.Yukihiro "Matz" Matsumoto
2020-10-12Use `mrb_funcall_id()` extensively.Yukihiro "Matz" Matsumoto
Except for support files e.g. `mruby-test/driver.c`, which are not target of symbol collection via `rake gensym`.
2020-10-12Fix argument error when built with MRB_WITHOUT_FLOAT flagssmallkirby
Fixed inproper argument of mrb_fixnum_value() called in integral_div(), when built with MRB_WITHOUT_FLOAT flag. Co-authored-by: taiyoslime <[email protected]> Co-authored-by: n4o847 <[email protected]>
2020-08-08Return `NaN` for `0/0`; d8e060dYukihiro "Matz" Matsumoto
2020-08-08Should not use `mrb_float_value()` with `MRB_WITHOUT_FLOAT`.Yukihiro "Matz" Matsumoto
2020-08-07Avoid `division by zero` undefined behavior.Yukihiro "Matz" Matsumoto
2020-06-25Remove unnecessary `break` from `numeric.c`.Yukihiro "Matz" Matsumoto
2020-06-20Add `mrb_get_arg1()` that retrieves single (and only) argument.Yukihiro "Matz" Matsumoto
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-03Merge pull request #4800 from ↵Yukihiro "Matz" Matsumoto
shuujii/set-MRB_STR_ASCII-flag-to-some-stringize-methods Set `MRB_STR_ASCII` flag to some stringize methods
2020-05-07Update `cmpnum` document.Yukihiro "Matz" Matsumoto
`cmpnum` function may return `nil` on error.
2019-11-11Fix argument specs to `Integer`KOBAYASHI Shuji
2019-10-31Set `MRB_STR_ASCII` flag to some stringize methodsKOBAYASHI Shuji
- `Fixnum#to_s`, `Fixnum#inspect` - `Float#to_s`, `Float#inspect` - `NilClass#to_s`, `NilClass#inspect` - `FalseClass#to_s`, `FalseClass#inspect` - `TrueClass#to_s`, `TrueClass#inspect` - `Time#to_s`, `Time#inspect`
2019-09-26Use type predicate macros instead of `mrb_type` if possibleKOBAYASHI Shuji
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for all `enum mrb_vtype`).
2019-09-18Remove `mrb_get_args(mrb, "")`; ref 30f37872KOBAYASHI Shuji
2019-09-17Fix `Fixnum#(to_s|inspect)` argument specsKOBAYASHI Shuji
Before this patch: $ bin/mruby -e 'p 3.to_s(2)' trace (most recent call last): [0] -e:1 -e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError) After this patch: $ bin/mruby -e 'p 3.to_s(2)' "11"
2019-09-14Remove `mrb_funcall` from `<=>` operations.Yukihiro "Matz" Matsumoto
2019-09-07Revert part of #4225Yukihiro "Matz" Matsumoto
Since in mruby, Integer and Float interchange frequently (mostly on overflow), so adding explicit `.0` can cause problems sometimes. For example: https://github.com/mattn/mruby-json/pull/40 https://github.com/pepabo/mruby-msd/pull/13 https://github.com/mattn/mruby-json/pull/42
2019-08-06Add `mrb_noreturn` to `cmperr()` in `src/numeric.c`KOBAYASHI Shuji
2019-08-05Use new specifiers/modifiers of `mrb_vfromat()`KOBAYASHI Shuji
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in my environment than before the introduction of new specifiers/modifiers (5116789a) with this change. ------------+-------------------+-------------------+-------- BINARY | BEFORE (5116789a) | AFTER (This PR) | RATIO ------------+-------------------+-------------------+-------- mruby | 593416 bytes | 593208 bytes | -0.04% libmruby.a | 769048 bytes | 767264 bytes | -0.23% ------------+-------------------+-------------------+-------- BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613, so I put it back.
2019-07-31Avoid `MRB_INT_MIN` to apply `fixdivmod`.Yukihiro "Matz" Matsumoto
`MRB_INT_MIN` is the only integer value that has no corresponding positive integer value (i.e. `-MRB_INT_MIN` = `MRB_INT_MIN`).
2019-07-31Normalize floating point negative zero to positive zero in `flodivmod'.Yukihiro "Matz" Matsumoto
2019-07-31Should return +/- infinity for float division by zero.Yukihiro "Matz" Matsumoto
2019-07-31Use `NULL` instead of `0` for null pointers.Yukihiro "Matz" Matsumoto
2019-07-30Fixed integer overflow in `lshift`.Yukihiro "Matz" Matsumoto
2019-07-22No rounding needed if 'ndigits` is bigger than `DBL_DIG+2`; fix #4566Yukihiro "Matz" Matsumoto
2019-07-13Avoid `mrb_funcall()` if possible using `mrb_Float()`; ref #4555Yukihiro "Matz" Matsumoto
2019-05-30Fix inverted compilation condition; fix #4478Yukihiro "Matz" Matsumoto
2019-05-21Update ISO section number for some Numeric methods.Yukihiro "Matz" Matsumoto
2019-05-21Export `mrb_int_value` that converts `mrb_float` to `Fixnum`.Yukihiro "Matz" Matsumoto
Or `Float` if `mrb_float` value is too big (or too small) to fit in `mrb_int`. The `_int_` in `mrb_int_value` means `Integral` module, which represents integer-like values in mruby.
2019-05-21Silence the return value warnings from gcc; ref 237a57bYukihiro "Matz" Matsumoto
2019-05-21Move `**`,`/`,`quo`,`div` and comparison methods to Integral from NumericKOBAYASHI Shuji
Having these methods in Numeric can get in the way of creating subclasses of Numeric because they only support Fixnum and Float.
2019-05-20Add new functions for numerical operation; ref 237a57bYukihiro "Matz" Matsumoto
New functions: * mrb_num_plus(mrb, x, y) * mrb_num_minus(mrb, x, y) * num_num_mul(mrb, x, y)
2019-05-18Move `Numeric#__coerce_step_counter` to `Integral`KOBAYASHI Shuji
This method is only used in `Integral#step`
2019-05-17Make unused functions private.Yukihiro "Matz" Matsumoto
* mrb_fixnum_plus() * mrb_fixnum_minus() * mrb_fixnum_mul()
2019-05-17Remove unused `mrb_num_div()` function.Yukihiro "Matz" Matsumoto
2019-05-17Move `Numeric#div` to the core.Yukihiro "Matz" Matsumoto
2019-05-17Make `flo_rount` to return `Integeral`.Yukihiro "Matz" Matsumoto
2019-05-17Change the `num.divmod(float)` to return `[int,num]`.Yukihiro "Matz" Matsumoto
2019-05-17Add a new function `mrb_int_value`.Yukihiro "Matz" Matsumoto
This function returns `Fixnum` if the value fits in `mrb_int`, otherwise it returns `Float` value (mruby behavior of handling integers).