Yukihiro "Matz" Matsumoto
9c5dc42e59
small cosmetic changes.
...
I prefer `i++` style unless absolutely necessary.
This commit is an addition to 41e4148.
2022-11-19 17:11:56 +09:00
fn ⌃ ⌥
f3ec5f744f
rational.c: implement nil.to_r and Float#to_r
2022-10-24 17:31:52 -07:00
dearblue
bbb04d257f
Add default sauce to #add_dependency
2022-10-21 22:27:20 +09:00
Yukihiro "Matz" Matsumoto
579379c517
rational.c (rational_hash): generate hash code from rational numbers.
2022-08-06 06:43:42 +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
67f47c9b42
rational.c (mrb_rational_copy): allow copying of rational numbers.
2022-07-11 11:19:22 +09:00
Yukihiro "Matz" Matsumoto
cf7aa74f7c
mruby-rational/rational.c: update error message.
2022-06-21 22:17:17 +09:00
Yukihiro "Matz" Matsumoto
019a2ddff4
mruby-rational/rational.c: implement Rational#**; close #5724
2022-06-21 16:53:17 +09:00
Yukihiro "Matz" Matsumoto
04de280997
mruby-rational/rational.c: wrap prototype with mrb_float
...
When `MRB_NO_FLOAT` is defined, `mrb_float` is not defined.
2022-06-21 16:37:32 +09:00
Yukihiro "Matz" Matsumoto
6f78cd6c99
mruby-rational/rational.c: remove unused prototype [ci skip]
2022-06-21 14:01:38 +09:00
dearblue
23611332d9
Introduced mrb_static_assert_object_size()
...
Asserts the size of the object structure is less than or equal to 6 words.
2022-05-28 11:08:27 +09:00
Yukihiro "Matz" Matsumoto
fe03e01078
numeric.c: enhance integer division to support Rational and Complex.
...
No longer need to override division methods in mrbgems.
2022-03-18 12:27:46 +09:00
Yukihiro "Matz" Matsumoto
2772e07dc8
rational.c: avoid mrb_funcall; call functions directly.
2022-03-12 13:31:38 +09:00
Yukihiro "Matz" Matsumoto
10001ff67f
rational.c, complex.c: expose arithmetic operation functions.
...
* mrb_{rational,complex}_{add,sub,mul,div}
2022-03-12 08:35:07 +09:00
Yukihiro "Matz" Matsumoto
b118ba9fb3
rational.c: avoid indirect calls using mrb_funcall().
2022-02-25 17:53:55 +09:00
Yukihiro "Matz" Matsumoto
c088af87b8
object.c: Call functions directly from mrb_ensure_int_type(); #5622
2022-01-05 19:00:14 +09:00
dearblue
ac22a63ae3
Call functions directly from mrb_ensure_float_type()
...
ref. commit 7f40b645d2
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-12-31 19:12:11 +09:00
Yukihiro "Matz" Matsumoto
a9a2dcd3cc
rational.c: avoid recursion between rational_eq and complex_eq.
2021-10-14 22:48:54 +09:00
dearblue
5a57602860
Organize the include of header files
...
- `#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-08-21 15:42:57 +09:00
dearblue
cc95e346fd
Added MRB_OBJ_ALLOC() macro that does not require a cast
...
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-20 11:08:28 +09:00
John Bampton
dab5502e8a
Run pre-commit with GitHub Actions
...
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-06-16 08:34:54 +10:00
Yukihiro "Matz" Matsumoto
5eebbd7df2
Global renaming regarding integer and float.
...
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-17 15:07:05 +09:00
Yukihiro "Matz" Matsumoto
fbbcee835f
rational.c: update function prefixes.
...
To be consistent, functions with `rational_` prefix implements methods,
functions with `rat_` prefix are utility functions.
2021-05-17 13:39:51 +09:00
KOBAYASHI Shuji
c6911c54e5
Remove unused #include in complex.c and rational.c
2021-04-20 16:42:40 +09:00
Yukihiro "Matz" Matsumoto
9038a1ca40
rational.c: add explicit cast from mrb_int to mrb_float.
2021-03-31 11:39:59 +09:00
Yukihiro "Matz" Matsumoto
a5244b02c5
numeric.c: function renaming.
...
- `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-28 08:35:29 +09:00
Yukihiro "Matz" Matsumoto
c2f929ad0f
Move default Integer#/ from rational.c to complex.c.
2021-03-27 12:38:16 +09:00
Yukihiro "Matz" Matsumoto
9492e389b8
rational.rb: add test for arithmetic operators.
...
Tests for (`Float` or `Integer`) `op` `Rational`.
2021-03-26 07:37:50 +09:00
Yukihiro "Matz" Matsumoto
6d89047637
rational.c: fix wrong funcall method in rational_mul.
2021-03-25 22:31:32 +09:00
Yukihiro "Matz" Matsumoto
0aff83dcdc
rational.c: inline mrb_rational_eq().
...
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-25 08:28:41 +09:00
Yukihiro "Matz" Matsumoto
4a0c14e3bd
rational.c: implement Rational#<=> in C.
2021-03-24 19:49:20 +09:00
Yukihiro "Matz" Matsumoto
3a2075343c
rational.c: implement Rational#/ and #quo in C.
2021-03-24 19:21:38 +09:00
Yukihiro "Matz" Matsumoto
f05f6f4d11
rational.c: implement Rational#* in C.
2021-03-24 19:11:02 +09:00
Yukihiro "Matz" Matsumoto
9d058342a5
rational.c: implement Rational#- in C.
2021-03-24 19:01:58 +09:00
Yukihiro "Matz" Matsumoto
7a35b64251
fixup! rational.c: prepare utility function rat_to_flo().
2021-03-24 19:01:38 +09:00
Yukihiro "Matz" Matsumoto
ac4fe26fbb
rational.c: prepare utility function rat_to_flo().
...
This function takes `struct mrb_rational*` and returns converted
`mrb_float` value.
2021-03-24 18:59:35 +09:00
Yukihiro "Matz" Matsumoto
7ca7bee9b3
rational.c: implement Rational#+ in C.
2021-03-24 13:57:49 +09:00
Yukihiro "Matz" Matsumoto
092bba64e7
rational.c: check integer overflow in rational_minus.
2021-03-24 13:28:01 +09:00
Yukihiro "Matz" Matsumoto
ec456e5b18
Use mrb_num_div_flo for float division.
...
This function handles zero division properly. Also fixed bugs that multiply
numbers instead of division.
2021-03-24 10:54:24 +09:00
Yukihiro "Matz" Matsumoto
98799aa6b8
Fix infinite recursive call bugs in integer division.
2021-03-24 10:52:31 +09:00
Yukihiro "Matz" Matsumoto
68cf8346cd
Use global defines for Rational and Complex.
2021-03-22 10:59:35 +09:00
Yukihiro "Matz" Matsumoto
e21f293de5
rational.c: fix MRB_TT_RATIONAL and MRB_TT_COMPLEX confusion.
2021-03-20 18:03:11 +09:00
Yukihiro "Matz" Matsumoto
08f9d5bab5
rational.c: overhaul rational operators.
...
- 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-19 10:37:10 +09:00
Yukihiro "Matz" Matsumoto
aa5b7fbd80
i_gcd() does not work for MRB_INT_MIN.
2021-02-08 21:18:50 +09:00
Yukihiro "Matz" Matsumoto
2e33c2d120
Remove unnecessary bit shift in rational_new_f.
2021-01-28 08:47:16 +09:00
Yukihiro "Matz" Matsumoto
17ecf14511
Revert "Minimize the changes in #5277 "
...
This reverts commit dc51d89ac2 .
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto
0903e2a72e
Silence 'loss of data' warnings.
2021-01-25 15:45:32 +09:00
Yukihiro "Matz" Matsumoto
efef4541aa
Fix a bug for the case frexp() return Infinity.
2021-01-25 15:44:59 +09:00
Yukihiro "Matz" Matsumoto
23e5c08e31
Should use a limit for 32 bit platform; ref 05a8cc44
2021-01-25 15:44:59 +09:00
Yukihiro "Matz" Matsumoto
05a8cc44cc
Define RAT_INT_LIMIT for 32 bit platforms.
2021-01-24 22:21:56 +09:00