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

[WIP] Adding VM Float API #615

Closed
wants to merge 5 commits into from
Closed

[WIP] Adding VM Float API #615

wants to merge 5 commits into from

Conversation

SD10
Copy link
Member

@SD10 SD10 commented Mar 7, 2018

Hey everyone 👋,

I started working on #484. However, I'm new to Goby, Go, and Ruby 😂

This is classified as work in progress because I wanted to make sure I'm doing things correctly before trying to implement the full API. Any feedback is appreciated!

Referenced from the Ruby Ver. 2.4.1. Float data type API:

  • Constant Float::INFINITE stands for the number is infinite

  • Float#abs Return positive number of the float. "Formally as the distance between 0 to the number of the float in 1-dimensional axis ..."

  • Float#angle (and Float#arg) If positive -> return 0; else -> return PI

  • Float#ceil Returns smallest number greater than or equal to the receiver

  • Float#floor Returns largest number smaller than or equal to the receiver

  • Float#round Rounds float to a given precision in decimal digits (default 0 digits). Precision may be negative. Returns a floating point number when n digits is more than zero.

  • Float#finite? Returns true if receiver isn't equal to Float::INFINITE

  • Float#infinite? Returns true if receiver is equal to Float::INFINITE

  • Float#divmod Returns array which is in format of [ (Integer) Quotient, (Float) Remainder ]

  • Float#positive? Returns true if float number is larger than 0.0

  • Float#negative? Returns true if float number is less than 0.0

  • Float#zero? Returns true if float number is equal to 0.0

Lower priority:

  • Constant Float::NAN stands for "Not a Number"
  • Float#nan? Returns true if receiver is equal to Float::NAN
  • Float#rationalize Convert to something called Rational data type (Currently not supported but from my point of view, it is worth being addressed in this issue)

This closes #484

@codecov
Copy link

codecov bot commented Mar 7, 2018

Codecov Report

Merging #615 into master will decrease coverage by 0.06%.
The diff coverage is 72.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #615      +/-   ##
==========================================
- Coverage   82.94%   82.88%   -0.07%     
==========================================
  Files          56       56              
  Lines        7501     7544      +43     
==========================================
+ Hits         6222     6253      +31     
- Misses       1027     1033       +6     
- Partials      252      258       +6
Impacted Files Coverage Δ
vm/float.go 82.25% <72.09%> (-3.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c52b53e...8146078. Read the comment docs.

@st0012
Copy link
Member

st0012 commented Mar 8, 2018

@SD10 for test cases, can you include Ruby doc's examples? Like https://ruby-doc.org/core-2.4.0/Float.html#method-i-ceil

@SD10
Copy link
Member Author

SD10 commented Mar 26, 2018

I'm implementing divmod now. All the others require NAN and INFINITE to be defined.

@st0012 How do you think we should implement these constants? We also need PI

@64kramsystem
Copy link
Member

64kramsystem commented Mar 26, 2018

I'm implementing divmod now. All the others require NAN and INFINITE to be defined.
@st0012 How do you think we should implement these constants? We also need PI

I had a look at the IEEE754 specification, the MRI source code, and the Golang API, and there are a few interesting points:

  • Positive/negative infinity map to a single value each, different only in the sign. For this reason, Ruby has only a single Float::INFINITY constant, the positive infinity (the sign can be used in the language grammar for expressing the negative infinity, since it matches the binary representation)
  • NaN is different, as there is no single value representing it. I'm a bit perplexed by the Ruby constant for it - notice that the documentation (Float::NAN [is] An expression representing a value which is “not a number”) in fact says a value, not the value. On the other hand, although Float::NaN can't be used in equality testing against itself, it can still be used in arithmetic, as it makes mathematical sense.

To summarize, based on my understanding, I think that:

  • at least one Infinity constant, the positive one, is required; Go has APIs for getting the value (math.Inf);
  • the Ruby Float#infinite? method is important;
  • the Float#nan? method is required;
  • I would leave the Float::NAN constant aside for now, waiting for somebody opening an issue with a use case.

@SD10
Copy link
Member Author

SD10 commented Mar 26, 2018

  • the Ruby Float#infinite? method is important;
  • the Float#nan? method is required;

@saveriomiroddi Thanks for writing that up. I totally overlooked that we can still implement those methods.

@st0012
Copy link
Member

st0012 commented Mar 26, 2018

@saveriomiraddi thanks for the information, learned a lot 🙇‍♂️

@st0012 st0012 modified the milestones: version 0.1.9, version 0.1.10 Apr 2, 2018
@eliothedeman
Copy link
Contributor

Float#nan? is pretty trivial to impliment.

a = Float::NAN
return a != a

NAN is the only float value for which this will be true.

@ghost ghost assigned st0012 May 9, 2018
@st0012
Copy link
Member

st0012 commented May 9, 2018

@SD10 Is it ok if I take over this PR?

@SD10
Copy link
Member Author

SD10 commented May 9, 2018

@st0012 Yes, no problems here 😓 Sorry

Sent with GitHawk

@st0012 st0012 mentioned this pull request May 10, 2018
7 tasks
@st0012
Copy link
Member

st0012 commented Jun 10, 2018

@SD10 Since we have #664 for continuing the task, I'll close this

@st0012 st0012 closed this Jun 10, 2018
@ghost ghost removed the in progress label Jun 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VM Float API Implementation
4 participants