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

Improve compatibility to CRuby for Float#to_s #4225

Merged

Conversation

@shuujii
Copy link
Contributor

@shuujii shuujii commented Jan 13, 2019

Bfore:

p Float::INFINITY.to_s  #=> "inf"
p 50.0.to_s             #=> "50"
p 1e20.to_s             #=> "1e+20"

After / CRuby:

p Float::INFINITY.to_s  #=> "Infinity"
p 50.0.to_s             #=> "50.0"
p 1e20.to_s             #=> "1.0e+20"
shuujii added 2 commits Jan 13, 2019
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"
@matz matz merged commit 348526e into mruby:master Jan 14, 2019
3 checks passed
3 checks passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@shuujii shuujii deleted the shuujii:improve-compatibility-to-cruby-for-float-to_s branch Jan 16, 2019
@take-cheeze
Copy link
Contributor

@take-cheeze take-cheeze commented Sep 6, 2019

Not a revert request but we should be careful that mruby promotes overflowed integer since mruby doesn't have BigInt.
Related issues cause by this PR:
mattn/mruby-json#40
pepabo/mruby-msd#13
mattn/mruby-json#42

@matz
Copy link
Member

@matz matz commented Sep 6, 2019

OK, I will revert part of this PR.

matz added a commit that referenced this pull request Sep 7, 2019
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.

For example:
mattn/mruby-json#40
pepabo/mruby-msd#13
mattn/mruby-json#42
@matz
Copy link
Member

@matz matz commented Sep 7, 2019

So I removed explicit .0 addition at the end from Float#to_s. @take-cheeze could you check it solves mrbgems problems?

@take-cheeze
Copy link
Contributor

@take-cheeze take-cheeze commented Sep 9, 2019

LGTM now

@matz
Copy link
Member

@matz matz commented Sep 9, 2019

Thank you.

@shuujii
Copy link
Contributor Author

@shuujii shuujii commented Sep 10, 2019

Is it okay in the case of exponential notation? (e.g. 3.0e+45)

@matz
Copy link
Member

@matz matz commented Sep 10, 2019

I think so. The only reason I tried to remove the trailing .0 is integer compatibility, so exponential notation is not included.

shuujii added a commit to shuujii/mruby that referenced this pull request Oct 25, 2019
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test.

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
shuujii added a commit to shuujii/mruby that referenced this pull request Oct 25, 2019
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Aug 19, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Aug 20, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Aug 31, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Sep 17, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Sep 18, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Sep 29, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
matz added a commit that referenced this pull request Oct 14, 2020
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
ksekimoto added a commit to ksekimoto/mruby that referenced this pull request Jul 16, 2021
…ruby-for-float-to_s

Improve compatibility to CRuby for `Float#to_s`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants