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

Float documentation and unit tests #455

Merged
merged 34 commits into from
Jan 5, 2023
Merged

Conversation

luc-blaeser
Copy link
Contributor

@luc-blaeser luc-blaeser commented Dec 14, 2022

Improve Float.mo:

  • Documentation
  • Unit tests

Issues detected while refactoring:

Other possible areas of improvements for Float:

  • isNaN() function is missing
  • equals() comparison should consider numerical errors, by requiring an epsilon argument.
  • Positive infinity and negative infinity constants are missing.
  • compare function does not have a total order and is inconsistent, e.g. compare(NaN, NaN) == #greater.
  • neq function has a typo. Rename to neg

The suggestions for improvement are summarized in issue #456

@luc-blaeser luc-blaeser self-assigned this Dec 14, 2022
@luc-blaeser luc-blaeser marked this pull request as ready for review December 14, 2022 14:38
@kentosugama
Copy link
Contributor

+1 on having an equal with epsilon

src/Float.mo Outdated Show resolved Hide resolved
src/Float.mo Outdated Show resolved Hide resolved
@kentosugama
Copy link
Contributor

Woah that is a huge test file! :)

Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff - very thorough.

I would file an issue for items at the end of PR description (one blanket one or several smaller, up to you).

///
/// Float.neq(1.23) // => -1.23
/// ```
public func neq(x : Float) : Float { -x }; // Typo: Should be changed to `neg`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. I guess we could deprecate neq and add neg (but also in a separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prepare that in a separate PR. Good idea to deprecate the misspelled function.

src/Float.mo Outdated Show resolved Hide resolved
@kentosugama
Copy link
Contributor

kentosugama commented Jan 3, 2023

LGTM! Super thorough

Co-authored-by: Kento Sugama <[email protected]>
@luc-blaeser
Copy link
Contributor Author

Thanks a lot @crusso and @kentosugama for the review of this PR (with this huge unit test file).

@luc-blaeser luc-blaeser merged commit 3729c65 into master Jan 5, 2023
@luc-blaeser luc-blaeser deleted the luc/improve_float_test_doc branch January 5, 2023 08:36
ggreif pushed a commit that referenced this pull request Jan 5, 2023
Improve `Float.mo`:
* Documentation
* Unit tests

Issues detected while refactoring:
* dfinity/motoko#3646
* dfinity/motoko#3647

Other possible areas of improvements for `Float`:
* `isNaN()` function is missing
* `equals()` comparison should consider numerical errors, by requiring an epsilon argument.
* Positive infinity and negative infinity constants are missing.
* `compare` function does not have a total order and is inconsistent, e.g. `compare(NaN, NaN) == #greater`. 
* `neq` function has a typo. Rename to `neg`

The suggestions for improvement are summarized in issue #456
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.

3 participants