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

Add - Math module for std lib #180

Closed

Conversation

EvanPerreau
Copy link

Rounding

  • ceil(x: Num): Num - rounds up to the nearest integer
  • floor(x: Num): Num - rounds down to the nearest
  • round(x: Num): Num - rounds to the nearest integer

Absolute and sign

  • abs(x: Num): Num - absolute value
  • sign(x: Num): Num - sign function, returns -1, 0, or 1 depending on the sign of x

Min / Max

  • min(a: Num, b: Num): Num
  • max(a: Num, b: Num): Num

Power, root, exponential, logarithms and trigonometric

These can be easily evaluated using bc with flag -l

  • pow(base: Num, exponent: Num): Num - power function
  • sqrt(x: Num): Num - square root
  • exp(x: Num): Num - exponential function
  • log(x: Num): Num - natural logarithm
  • log10(x: Num): Num - base-10 logarithm
  • sin(x: Num): Num - sine
  • cos(x: Num): Num - cosine
  • tan(x: Num): Num - tangent

Copy link
Member

@b1ek b1ek left a comment

Choose a reason for hiding this comment

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

why are there two files with identical functions? the main.ab and math.ab

@EvanPerreau
Copy link
Author

It's because actually, the pull request Split stdlib into submodules isn't merge, for unit test, I need to put all functions in main.ab, but for help us to split stdlib in future, I also put all functions in math.ab

@b1ek
Copy link
Member

b1ek commented Jun 13, 2024

then its probably better to wait for a decicion on #152 and then merge this one

@EvanPerreau
Copy link
Author

yes, ok !

@UrbanCoffee
Copy link

Hello. I just wanted to add that the implementations of floor and ceil are not entirely correct. They return the wrong value for negative inputs. Additionally, if the input x is an integer, ceil returns x+1 rather than just x.

@Ph0enixKM
Copy link
Collaborator

Ph0enixKM commented Jun 13, 2024

We'll have to write a separate file for testing the math library. We need a lot of good tests to keep this working

@Ph0enixKM Ph0enixKM linked an issue Jun 13, 2024 that may be closed by this pull request
@b1ek
Copy link
Member

b1ek commented Jun 13, 2024

We'll have to write a separate file for testing the math library. We need a lot of good tests to keep this working

that should probably be as a submod to stlib.rs, like stdlib/math.rs ig

Fix - Correction of floor, ceil and round functions
Fix - Correction floor, ceil and round functions
@EvanPerreau
Copy link
Author

Hello. I just wanted to add that the implementations of floor and ceil are not entirely correct. They return the wrong value for negative inputs. Additionally, if the input x is an integer, ceil returns x+1 rather than just x.

Hello, I fix this bug :)

@b1ek b1ek added the pr/breaking This PR introduces a breaking change label Jun 22, 2024
@b1ek b1ek removed the pr/breaking This PR introduces a breaking change label Jun 22, 2024
@Mte90
Copy link
Member

Mte90 commented Jul 4, 2024

Hi @EvanPerreau are you still working on this PR?

@Mte90
Copy link
Member

Mte90 commented Jul 16, 2024

@EvanPerreau with the latest changes we have now a file for math stuff.
Are you still working on this?

@Ph0enixKM
Copy link
Collaborator

@Mte90 I'll contact him personally

@Ph0enixKM
Copy link
Collaborator

@Mte90 it seems that @EvanPerreau left the discord server and I'm no longer able to message him. Let's close this PR for now. We can reopen it later

@Ph0enixKM Ph0enixKM closed this Jul 16, 2024
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.

✨ Proposal for Comprehensive Mathematical Module in Amber
5 participants