summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-rational/src/rational.c
AgeCommit message (Collapse)Author
2022-01-05object.c: Call functions directly from `mrb_ensure_int_type()`; #5622Yukihiro "Matz" Matsumoto
2021-12-31Call functions directly from `mrb_ensure_float_type()`dearblue
ref. commit 7f40b645d2773c8f50c48ae4adf90488e164da55 Currently, the build configurations `MRB_USE_COMPLEX` and `MRB_USE_RATIONAL` are not listed in the documentation. In other words, they are hidden settings. They are defined in `mrbgems/mruby-{complex,rational}/mrbgem.rake`. So this patch assumes that it is safe to refer to these functions in core-gems directly from core functions. However, applications that link with `libmruby_core.a` will have compatibility issues. In fact, `mrbgems/mruby-bin-mrbc` links with `libmruby_core.a`, so I had to prepare a dummy function.
2021-10-14rational.c: avoid recursion between `rational_eq` and `complex_eq`.Yukihiro "Matz" Matsumoto
2021-08-21Organize the include of header filesdearblue
- `#include <math.h>` is done in `mruby.h`. Eliminate the need to worry about the `MRB_NO_FLOAT` macro. - Include mruby header files before standard header files. If the standard header file is already placed before `mruby.h`, the standard header file added in the future tends to be placed before `mruby.h`. This change should some reduce the chances of macros that must be defined becoming undefined in C++ or including problematic header files in a particular mruby build configuration.
2021-06-20Added `MRB_OBJ_ALLOC()` macro that does not require a castdearblue
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-16Run pre-commit with GitHub ActionsJohn Bampton
Running pre-commit with GitHub Actions now gives us more tests and coverage Remove duplicate GitHub Actions for merge conflicts and trailing whitespace Remove duplicate checks for markdownlint and yamllint from the GitHub Super-Linter Add new custom pre-commit hook running with a shell script to sort alphabetically and uniquify codespell.txt Add new pre-commit hook to check spelling with codespell https://github.com/codespell-project/codespell Fix spelling
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-17rational.c: update function prefixes.Yukihiro "Matz" Matsumoto
To be consistent, functions with `rational_` prefix implements methods, functions with `rat_` prefix are utility functions.
2021-04-20Remove unused `#include` in `complex.c` and `rational.c`KOBAYASHI Shuji
2021-03-31rational.c: add explicit cast from `mrb_int` to `mrb_float`.Yukihiro "Matz" Matsumoto
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-27Move default `Integer#/` from `rational.c` to `complex.c`.Yukihiro "Matz" Matsumoto
2021-03-25rational.c: fix wrong `funcall` method in `rational_mul`.Yukihiro "Matz" Matsumoto
2021-03-25rational.c: inline `mrb_rational_eq()`.Yukihiro "Matz" Matsumoto
It removes non-static function, so that strictly saying, it's an incompatible change. But the function was added recently and I am sure no one uses it yet.
2021-03-24rational.c: implement `Rational#<=>` in C.Yukihiro "Matz" Matsumoto
2021-03-24rational.c: implement `Rational#/` and `#quo` in C.Yukihiro "Matz" Matsumoto
2021-03-24rational.c: implement `Rational#*` in C.Yukihiro "Matz" Matsumoto
2021-03-24rational.c: implement `Rational#-` in C.Yukihiro "Matz" Matsumoto
2021-03-24fixup! rational.c: prepare utility function `rat_to_flo()`.Yukihiro "Matz" Matsumoto
2021-03-24rational.c: prepare utility function `rat_to_flo()`.Yukihiro "Matz" Matsumoto
This function takes `struct mrb_rational*` and returns converted `mrb_float` value.
2021-03-24rational.c: implement `Rational#+` in C.Yukihiro "Matz" Matsumoto
2021-03-24rational.c: check integer overflow in `rational_minus`.Yukihiro "Matz" Matsumoto
2021-03-24Use `mrb_num_div_flo` for float division.Yukihiro "Matz" Matsumoto
This function handles zero division properly. Also fixed bugs that multiply numbers instead of division.
2021-03-24Fix infinite recursive call bugs in integer division.Yukihiro "Matz" Matsumoto
2021-03-22Use global defines for `Rational` and `Complex`.Yukihiro "Matz" Matsumoto
2021-03-20rational.c: fix `MRB_TT_RATIONAL` and `MRB_TT_COMPLEX` confusion.Yukihiro "Matz" Matsumoto
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-02-08`i_gcd()` does not work for `MRB_INT_MIN`.Yukihiro "Matz" Matsumoto
2021-01-28Remove unnecessary bit shift in `rational_new_f`.Yukihiro "Matz" Matsumoto
2021-01-26Revert "Minimize the changes in #5277"Yukihiro "Matz" Matsumoto
This reverts commit dc51d89ac22acc60b9bfeed87115863565b74085.
2021-01-25Silence 'loss of data' warnings.Yukihiro "Matz" Matsumoto
2021-01-25Fix a bug for the case `frexp()` return `Infinity`.Yukihiro "Matz" Matsumoto
2021-01-25Should use a limit for 32 bit platform; ref 05a8cc44Yukihiro "Matz" Matsumoto
2021-01-24Define `RAT_INT_LIMIT` for 32 bit platforms.Yukihiro "Matz" Matsumoto
2021-01-24Detect integer overflow in `rational_new_f()`.Yukihiro "Matz" Matsumoto
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-13Rational denominator should not be zero.Yukihiro "Matz" Matsumoto
2021-01-12Silence Windows warnings (cast and `setmode`).Yukihiro "Matz" Matsumoto
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.
2021-01-10Fix CI failure on Windows environment.Yukihiro "Matz" Matsumoto
`1L` on Windows means `32 bit int`.
2021-01-09Fix wrong float to rational conversion in 32 bit mode.Yukihiro "Matz" Matsumoto
2021-01-09Convert float number to rational by decoding mantissa.Yukihiro "Matz" Matsumoto
2021-01-02Avoid `int64_t` on 32 bit platforms.Yukihiro "Matz" Matsumoto
2021-01-02Check `NaN` and `Infinity` before converting `Float` to `Rational`.Yukihiro "Matz" Matsumoto
2020-12-24Avoid division by zero in `rational_to_f()`.Yukihiro "Matz" Matsumoto
2020-12-15refactor: remove trailing whitespace from C, Header, Ruby and YAML filesJohn Bampton
Lint
2020-11-26Avoid integer overflow in `rational_new`.Yukihiro "Matz" Matsumoto
2020-11-17Check division overflow (`MRB_INT_MIN` and `-1`).Yukihiro "Matz" Matsumoto
2020-11-04Add cast to silence int conversion warnings.Yukihiro "Matz" Matsumoto