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

Adding a Difference method to the Math module #14740

Open
foxwyn opened this issue Jun 21, 2024 · 3 comments
Open

Adding a Difference method to the Math module #14740

foxwyn opened this issue Jun 21, 2024 · 3 comments

Comments

@foxwyn
Copy link

foxwyn commented Jun 21, 2024

Discussion

  • I would like to see the addition of a Difference method added to the Math module.
  • Reason being, I'm surprised to not find it available anywhere in stdlib, despite being a fundamental math operation.
  • I propose adding a Math.diff(a,b) method to the Math module for each type (ints, floats, etc).

Difference is just the smaller number subtracted from the larger number to return the gap between.

Math.max(a,b) - Math.min(a,b)

I would be willing to make a pr.

@HertzDevil
Copy link
Contributor

That would be just (a - b).abs, which I don't think is that difficult to type out? Which other stdlibs have this method?

@foxwyn
Copy link
Author

foxwyn commented Jun 21, 2024

That would be just (a - b).abs, which I don't think is that difficult to type out? Which other stdlibs have this method?

I went digging for a difference method after trying (a-b).abs first. I had assumed I misunderstood the math and needed something else, but it would seem my error was somewhere else in my code, because '(a-b).abs' works in isolation as I would expect it to.

So that's my mistake, I suppose that is sort of silly now.

That being said, I don't know of it being a thing in other languages stdlibs. But it seems like such a fundamental operation for two numbers, I guess I'm just surprised it isn't inbuilt - especially when there are tons of trig functions. If there are absolute basics of plus, minus, multiply, and divide, and beyond basics of trig functions, you'd think difference falling somewhere in-between would be included.

@foxwyn
Copy link
Author

foxwyn commented Jun 28, 2024

@ysbaddaden Glad you reference #14587, because that was also one of the solutions I tried, and was disappointed to find it didn't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants