summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
AgeCommit message (Collapse)Author
2021-06-15numeric.c: restore `fmt` argument for backward compatibility.Yukihiro "Matz" Matsumoto
`mrb_float_to_str()` used to take `fmt` argument. We thought no one used the function, and OK to remove the argument. But at least `mruby-redis` gem used the function.
2021-05-31numeric.c: fixed a silly bug related to pointer decrement.Yukihiro "Matz" Matsumoto
2021-05-30numeric.c: introduce `mrb_int_to_cstr()` to dump `mrb_int`.Yukihiro "Matz" Matsumoto
* refactor `mrb_integer_to_str()` * refactor `mrb_str_format()`
2021-05-26fmt_fp.c: move mruby specific `mrb_float_to_str` to `numeric.c`Yukihiro "Matz" Matsumoto
2021-05-21fmt_fp.c: remove `fmt` argument from `mrb_float_to_str()`.Yukihiro "Matz" Matsumoto
With major refactoring to prepare removing `snprintf(3) calls.
2021-05-17Global renaming regarding `integer` and `float`.Yukihiro "Matz" Matsumoto
Consistent number conversion function names: * `mrb_value` to immediate (C) value * `mrb_int()` -> `mrb_as_int()` * `mrb_to_flo()` -> `mrb_as_float()` * `mrb_value` to `mrb_value` (converted) * `mrb_to_int()' * `mrb_Integer()` - removed * `mrb_Float()` -> `mrb_to_float` Consistent function name (avoid `_flo` suffix): * `mrb_div_flo()` -> `mrb_div_float`
2021-05-17Rename `mrb_fixnum_to_str` to `mrb_integer_to_str`.Yukihiro "Matz" Matsumoto
2021-05-17Rename `mrb_flo_to_fixnum` to `mrb_float_to_integer`.Yukihiro "Matz" Matsumoto
2021-04-24numeric.c: remove duplicated definitions; #5421Yukihiro "Matz" Matsumoto
Following functions are defined in `mrblib/numeric.c`: - `Integer#ceil` - `Integer#floor` - `Integer#round` - `Integer#truncate`
2021-04-24numeric.c: fix errors from `MRB_NO_FLOAT`; close #5421Yukihiro "Matz" Matsumoto
2021-04-21numeric.c: update error messages in `int_pow`; ref #5420Yukihiro "Matz" Matsumoto
2021-04-21numeric.c: fix `int_pow` to detect integer overflow; fix #5420Yukihiro "Matz" Matsumoto
2021-04-16feat(CI): add the GitHub Super LinterJohn Bampton
The GitHub Super Linter is a more robust and better supported tool than the current GitHub Actions we are using. Running these checks: ERROR_ON_MISSING_EXEC_BIT: true VALIDATE_BASH: true VALIDATE_BASH_EXEC: true VALIDATE_EDITORCONFIG: true VALIDATE_MARKDOWN: true VALIDATE_SHELL_SHFMT: true VALIDATE_YAML: true https://github.com/marketplace/actions/super-linter https://github.com/github/super-linter Added the GitHub Super Linter badge to the README. Also updated the pre-commit framework and added more documentation on pre-commit. Added one more pre-commit check: check-executables-have-shebangs Added one extra check for merge conflicts to our GitHub Actions. EditorConfig and Markdown linting. Minor grammar and spelling fixes. Update linter.yml
2021-03-28numeric.c: function renaming.Yukihiro "Matz" Matsumoto
- `mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)` - `mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)` They are internal function not supposed to be used outside of the core.
2021-03-19complex.c: overhaul complex operators.Yukihiro "Matz" Matsumoto
- define `MRB_TT_COMPLEX` - change object structure (`struct RComplex`) - add memory management for `MRB_TT_COMPLEX` - avoid operator overloading as much as possible - as a result, performance improved a log - should work with and without `Rational` defined
2021-03-19rational.c: overhaul rational operators.Yukihiro "Matz" Matsumoto
- define `MRB_TT_RATIONAL` - change object structure (`struct RRational`) - add memory management for `MRB_TT_RATIONAL` - avoid operator overloading as much as possible - implement division overloading in C - as a result, performance improved a lot
2021-03-19numeric.c: avoid integer overflow; close #5384Yukihiro "Matz" Matsumoto
Since `mruby` does not have `Bignum`, `Float#divmod` could overflow, so it will return `Float` values when the divided value does not fit in `mrb_int`. This behavior will be changed when `Bignum` is introduced to `mruby` in the future.
2021-03-19`Float#divmod` with zero should cause `ZeroDivisionError`; #5384Yukihiro "Matz" Matsumoto
2021-03-18`Float::NAN/0` should be `Float::NAN`; ref a0b3378b3KOBAYASHI Shuji
#### Before this patch: ```console $ bin/mruby -e 'p(Float::NAN/0)' Infinity ``` #### After this patch (same as Ruby): ```console $ bin/mruby -e 'p(Float::NAN/0)' NaN ```
2021-03-18numeric.c: float zero division should be infinity with sign kept; fix #5382Yukihiro "Matz" Matsumoto
2021-03-07bug(presym): Fix mrb_cmp declaration of <=> symbol for funcallRyan Lopopolo
2021-01-26Revert "Minimize the changes in #5277"Yukihiro "Matz" Matsumoto
This reverts commit dc51d89ac22acc60b9bfeed87115863565b74085.
2021-01-22Minimize the changes in #5277Yukihiro "Matz" Matsumoto
Instead of including `mruby/presym.h` everywhere, we provided the fallback `mruby/presym.inc` under `include/mruby` directory, and specify `-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`. So even when someone drops `-I<build-dir>/include` in compiler options, it just compiles without failure.
2021-01-21Merge branch 'avoid-including-presym.inc-in-existing-header-files' of ↵Yukihiro "Matz" Matsumoto
https://github.com/shuujii/mruby into shuujii-avoid-including-presym.inc-in-existing-header-files
2021-01-17Fix `int_quo` to do float division; fix #5268Yukihiro "Matz" Matsumoto
2021-01-17Make `mrb_to_flo()` to convert objects, not integer, not float; #5268Yukihiro "Matz" Matsumoto
Thinking `Ratinal` and `Complex` in mind.
2021-01-11Avoid including `presym.inc` in existing header filesKOBAYASHI Shuji
Addressed an issue where existing programs linking `libmruby.a` could only be built by adding `<build-dir>/include` to compiler's include path.
2020-12-24Check integer overflow in float bit operations.Yukihiro "Matz" Matsumoto
2020-12-15refactor: remove trailing whitespace from C, Header, Ruby and YAML filesJohn Bampton
Lint
2020-11-24Fix compiler errors from `MRB_NO_FLOAT`; #5185Yukihiro "Matz" Matsumoto
Also added `no-float.rb` target in `build_config`.
2020-11-21Update `Float#to_s` to keep trailing zero as CRuby does; ref 68cebb6Yukihiro "Matz" Matsumoto
2020-11-17Detect overflow in `flo_shift()`.Yukihiro "Matz" Matsumoto
2020-11-17Refactor integer division.Yukihiro "Matz" Matsumoto
2020-11-17Simplify `mrb_num_div_int()`.Yukihiro "Matz" Matsumoto
2020-11-14Integer operation should result in Integer.Yukihiro "Matz" Matsumoto
Should raise `RangeError` if the operation overflows.
2020-11-09Add range check before casting float to integer.Yukihiro "Matz" Matsumoto
2020-11-06Skip too big left shift in `flo_shift()`.Yukihiro "Matz" Matsumoto
2020-11-06Avoid negating `MRB_INT_MIN` which is impossible.Yukihiro "Matz" Matsumoto
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