60 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto d81d343f5b mruby-math: combine variable declaration with initialization 2025-10-26 23:30:14 +09:00
Yukihiro "Matz" Matsumoto e1f7a40d5a mruby-math: use mrb_define_module_id instead of mrb_define_module
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:23 +09:00
Yukihiro "Matz" Matsumoto 9736e37a31 mruby-math: rename mrb_math variable to math
unify declaration with initialization for cleaner code.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:23 +09:00
Yukihiro "Matz" Matsumoto 3a395b9e0a mruby-math: use MRB_SYM() and mrb_define_module_function_id()
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 23:55:22 +09:00
Yukihiro "Matz" Matsumoto 164a7302b1 mruby-math: add Math.expm1 and Math.log1p
Adds Math.expm1 and Math.log1p, which provide more accurate
calculations for exp(x) - 1 and log(1 + x) respectively,
especially for small values of x.

Co-authored-by: Gemini <gemini@google.com>
2025-08-23 06:49:56 +09:00
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00
Yukihiro "Matz" Matsumoto d7f7ea0d82 mruby-math: add README.md
The document is written by Google Jules.
2025-06-08 17:02:55 +09:00
Yukihiro "Matz" Matsumoto af3482d562 mruby-math: use erfc(x) instead of 1.0 - erf(x) 2024-01-09 08:01:28 +09:00
Yukihiro "Matz" Matsumoto 51c4c4716a mruby-math: use log1p(x) instead of log(1.0+x) 2024-01-09 07:59:42 +09:00
Yukihiro "Matz" Matsumoto 8a2e88390b mruby-math: reduce the scope of a local variable 2024-01-09 07:47:57 +09:00
Yukihiro "Matz" Matsumoto c1fc3219db mruby-math: fix spacing 2024-01-08 23:18:57 +09:00
Yukihiro "Matz" Matsumoto b4c936b533 use new E_EXCEPTION and E_STANDARD_ERROR; ref #5924 2023-02-10 15:21:38 +09:00
Yukihiro "Matz" Matsumoto d9bf3235d2 mruby-math/math.c: avoid mrb_get_args() if possible
When a method takes single argument, we can use lighter `mrb_get_arg1()`
instead of `mrb_get_args()`.
2023-01-24 09:15:20 +09:00
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
Yukihiro "Matz" Matsumoto 9f47f11abd math.c: update prototype style. 2022-09-05 07:30:12 +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
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
Yukihiro "Matz" Matsumoto 2268405fe6 test/math.rb: 10**30 could cause integer overflow; ref #5420 2021-04-21 22:04:20 +09:00
Yukihiro "Matz" Matsumoto 1cc20978cf Enlarge tolerance limit for float32; close #5329
Along with some refactoring on `mruby-math` tests.
2021-02-07 14:56:34 +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 dc51d89ac2 Minimize the changes in #5277
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-22 18:38:53 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
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-11 09:21:07 +09:00
Yukihiro "Matz" Matsumoto 2e30c68562 Move MRB_NO_FLOAT detection in mruby-math; #5185 2020-11-24 20:43:56 +09:00
Yukihiro "Matz" Matsumoto 08f61db6ee Skip some Math.atan2() tests.
Linux `atan2(3)` man page says:

```
If  y is positive infinity (negative infinity) and x is positive infinity,
+pi/4 (-pi/4) is re‐ turned.
```

But on Microsoft VC/MinGW, `atan2()` returns `NaN` if either of
arguments is infinite. So we skip those tests on the platforms.
2020-10-12 18:20:14 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* 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-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `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-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
KOBAYASHI Shuji d908a73b04 Add tests to Math 2019-12-07 20:50:56 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
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-08-05 13:18:50 +09:00
Yukihiro "Matz" Matsumoto 87d1b2a910 Improve conflict error message of Time and Math; ref #4576 2019-07-22 20:21:30 +09:00
dearblue c96b517ea2 Error needed/conflicts configuration
The purpose is to clarify the error if there is a needed/conflicts
configuration at compile time.
2019-07-14 00:29:17 +09:00
KOBAYASHI Shuji d1f937e1f4 Fix missing assertions in mruby-math test 2019-03-29 09:40:13 +09:00
Yukihiro "Matz" Matsumoto 42f240796f Use Mrbtest::FLOAT_TOLERANCE instead of Math::TORELANCE; ref #4345 2019-03-28 23:22:32 +09:00
Yukihiro "Matz" Matsumoto 3b92b642eb Break loop whem sum==0 to avoid zero division; ref #4345 2019-03-28 23:22:32 +09:00
Yukihiro "Matz" Matsumoto a26856f883 Use DBL_EPSILON instead of 1E-12; ref #4345 2019-03-28 23:22:32 +09:00
dearblue be980e9a7a Suppress __FreeBSD_version warns for FreeBSD 2018-12-23 17:23:51 +09:00
Tomasz Dąbrowski 553dbad2c6 fix: mrbgems\mruby-math\src\math.c(660): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 49e96a2e19 fix: mrbgems\mruby-math\src\math.c(491): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Yasuhiro Matsumoto 7cc33af2dc fix build on VS2012 2015-12-22 17:46:20 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
Paolo Bosetti 470fce5c90 Fix check for VisualStudio Version in mruby-math gem 2015-11-19 12:01:23 +01:00
Seba Gamboa 25c8e95365 Revert "Mark core gems with mrbgem tag"
This reverts commit 5cdcce8dbd.
2015-10-21 14:31:13 -03:00
Seba Gamboa 13b552538a Remove obvious warnings from docs 2015-10-20 12:48:31 -03:00
Seba Gamboa 5cdcce8dbd Mark core gems with mrbgem tag 2015-10-20 12:16:47 -03:00
bggd dc1dcba935 Update math.c 2014-08-22 16:51:04 +09:00
chasonr e23deaafc2 Improve replacement math functions for Visual C++. 2014-08-15 23:15:45 -04:00
kkkkkt 9c78fc8443 added Math.cos and Math.tan test case 2014-08-05 11:27:50 +09:00
cremno 405e8fbcd5 mruby-math: define and use Math::DomainError
Domain errors are detected as per ISO C99 and may differ from CRuby.
2014-05-02 23:48:25 +02:00
take_cheeze c73f8d4def move summary of mrbgems in default gembox to its spec 2014-03-17 00:34:24 +09:00