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

Include math.Floor and math.Ceil in builtin library. #742

Closed
kwshi opened this issue Aug 9, 2018 · 4 comments
Closed

Include math.Floor and math.Ceil in builtin library. #742

kwshi opened this issue Aug 9, 2018 · 4 comments

Comments

@kwshi
Copy link
Contributor

kwshi commented Aug 9, 2018

In #727, I suggested pouring all of Go's math library into a builtin library. It was suggested, instead, that these math functions be implemented directly in Elvish. This is a plausible idea, and I have started exploring/attempting that. However, the floating-point floor and ceiling functions (and more generally, floating point modulo) I think cannot be trivially/efficiently implemented in Elvish, because they rely on the underlying bitwise encoding of double-precision floating points.

Thus I think it would be nice to do one (or both) of two things:

  • Include floor and ceil (and maybe round, if we're feeling excited) in the builtin library.
  • Include floating-point modulo, i.e. math.Modf, as a builtin arithmetic operator. I might propose that this operator be name %f, and be used like %f 8.3 3 (outputs 2.3).
  • Include "truncated" (floored) division, a la Python. I propose this operator be named //, just as in Python. Then it would be used as // 8.3 3 (outputs 2).

The last suggestion is especially appealing to me, because it's, I think, the most minimal solution, and and everything else can be implemented using it.

@kwshi
Copy link
Contributor Author

kwshi commented Aug 9, 2018

Actually, better yet, I propose that the builtin modulo be replaced by a floating-point modulo. But I also still kinda like the idea of a // operator.

@xiaq
Copy link
Member

xiaq commented Aug 9, 2018

I agree. Let's put floor, ceil and round in a new math module, teach % how to deal with floats and add //.

@krader1961
Copy link
Contributor

A math: namespace was introduced by commit 2d8a045. Also, my PR #937 introduces the floor and ceil commands as part of resolving issue #727. So it would appear this is no longer an unresolved issue.

@krader1961
Copy link
Contributor

@xiaq, This can be closed now that PR #937 has been merged.

@xiaq xiaq closed this as completed May 7, 2020
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

No branches or pull requests

3 participants