summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
AgeCommit message (Collapse)Author
2019-11-11Fix argument specs to `Integer`KOBAYASHI Shuji
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).
2019-05-17Use `int64_t` instead of `mrb_int` in `int64_value`.Yukihiro "Matz" Matsumoto
2019-05-16Terminate float right shift if shift value is too big.Yukihiro "Matz" Matsumoto
2019-05-02Unify overflow error class for conversion to integer to `RangeError`KOBAYASHI Shuji
2019-04-15Fixed wrong function names; fix #4380Yukihiro "Matz" Matsumoto
2019-04-08Fix C99 style inline declaration; fix #4365Yukihiro "Matz" Matsumoto
2019-03-21Fix `Float#eql?`KOBAYASHI Shuji
2019-01-16Avoid runtime evaluation for `MRB_WITHOUT_FLOAT`KOBAYASHI Shuji
2019-01-13Improve compatibility to CRuby for `Float#to_s`KOBAYASHI Shuji
Bfore: Float::INFINITY.to_s #=> "inf" 50.0.to_s #=> "50" 1e20.to_s #=> "1e+20" After / CRuby: Float::INFINITY.to_s #=> "Infinity" 50.0.to_s #=> "50.0" 1e20.to_s #=> "1.0e+20"
2019-01-10Remove duplicate code in numeric.cKOBAYASHI Shuji
2019-01-04Integrate mrblib/float.rb into src/numeric.cKOBAYASHI Shuji
- Avoid hack for `MRB_WITHOUT_FLOAT` in build scripts - Avoid runtime dispatch for `MRB_WITHOUT_FLOAT`
2018-12-17Recover `#to_int`; ref #4177Yukihiro "Matz" Matsumoto
We have removed implicit conversion to strings using `to_int`. But some users still using `to_int` as a typical integer method, i.e. they do string check by code like: `obj.respond_to?(:to_int)`. So we have recovered the method.
2018-11-19Remove implicit conversion using `to_int` method.Yukihiro "Matz" Matsumoto
The ISO standard does not include implicit type conversion using `to_int`. This implicit conversion often causes vulnerability. There will be no more attacks like #4120. In addition, we have added internal convenience method `__to_int` which does type check and conversion (from floats).
2018-09-07Clear terminated spacedearblue
2018-08-06Small refactoring of `flodivmod()`.Yukihiro "Matz" Matsumoto
2018-05-01Update `MRB_FLO_TO_STR_FMT` to "%.16g"; fix #4016Yukihiro "Matz" Matsumoto
2017-11-22Provide shortcut comparison methods for numbers for performance.Yukihiro "Matz" Matsumoto
2017-11-04Merge branch 'master' of github.com:mruby/mrubyYAMAMOTO Masaya
2017-10-17Add `Numeric#{finite?,infinite?}`; CRuby2.4Yukihiro "Matz" Matsumoto
2017-10-11Add MRB_WITHOUT_FLOATYAMAMOTO Masaya
2017-09-27fix: src\numeric.c(1215): warning C4244: 'function': conversion from ↵Tomasz Dąbrowski
'mrb_int' to 'int', possible loss of data
2017-09-27fix: src\numeric.c(954): warning C4334: '<<': result of 32-bit shift ↵Tomasz Dąbrowski
implicitly converted to 64 bits (was 64-bit shift intended?)
2017-09-27fix: src\numeric.c(897): warning C4244: 'function': conversion from ↵Tomasz Dąbrowski
'mrb_int' to 'mrb_float', possible loss of data