Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added limitation about floating point numbers #6187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions doc/limitations.md
Expand Up @@ -253,3 +253,32 @@ def g(a: 1, b: a)
end
g(a:1)
```

## String to floating-point number conversion

Not only in Ruby, but in general, there is inevitably an error when converting floating-point numbers from strings.
The process to reduce this error as much as possible is complicated and expensive, and mruby omits the process.
Therefore, the results do not match those of CRuby.
This difference also applies to floating-point number literals written in Ruby code.

If your code has problems with the standard C library function `strtod()`,
consider whether it is acceptable to replace `strtod()` with `mrb_read_float()`.
Also, for the same reason, please consider replacing `printf("%f", num)` with `mrb_float_to_str()`.

#### Ruby [ruby 3.3.0 (2023-12-25 revision 5124f9ac75)]

```console
$ ruby33 -e 'p 4.9406564584124654418e-324'
5.0e-324
$ ruby33 -e 'p 0.0000000000000000000000000000000000007777777'
7.777777e-37
```

#### mruby [3.3.0 (2024-02-14)]

```console
$ bin/mruby -e 'p 4.9406564584124654418e-324'
0.0
$ bin/mruby -e 'p 0.0000000000000000000000000000000000007777777'
7.77777700000001e-37
```