Skip to content

Conversation

goodusername123
Copy link

@goodusername123 goodusername123 commented Jul 19, 2025

Adds a few extra functions to the math module including:

  • acosh, asinh, and atanh (missing hyperbolic functions)
  • cbrt
  • exp2
  • hypot
  • log2
  • round

The beginning basis of Lily's math module seems to have been constructed around the limitations of C89 of which a few other scripting languages restrict themselves to, however Lily seems to not be restricted to C89 as there are already other functions in the math library which require C99 or newer such as "is_nan" https://en.cppreference.com/w/c/numeric/math.html

I was tempted to just add every applicable math function from C99 as Lily already has all the math functions from C89 however I was not sure if that would be desired or not so for this PR I have just added a few that I think make the most sense. although I am curious to know if just flat out including almost all of the C99 math functions would be acceptable in the context of Lily, if so then Ill submit a PR after to add more or something maybe.

Adds a few extra functions to the math module including:
acosh, asinh, and atanh (missing hyperbolic functions)
cbrt
exp2
hypot
log2
round
@python-b5
Copy link
Contributor

python-b5 commented Jul 19, 2025

It's only mentioned on the website, but Lily targets C11. I don't know if that added any useful math functions, though.

Not sure if every math function necessarily needs to be added (though if there aren't too many, maybe it would be nice to ensure no use case is excluded...?), but as I'm using Lily for 2D game development, I would find eg. atan2 to be quite useful when working with angles. Right now a bit more manual code is required to accomplish that with plain atan. Additionally, while with bindings this simple this admittedly isn't all that critical, there should probably be tests for these new functions in test/prelude/test_pkg_math.lily.

You'll have to wait for @FascinatedBox for this, but do keep in mind it seems this GitHub repository is more or less just a mirror now. Active development/discussion is happening on GitLab.

@goodusername123
Copy link
Author

It's only mentioned on the website, but Lily targets C11. I don't know if that added any useful math functions, though.

AFAIK there haven't been any new math functions introduced to C since C99.

Not sure if every math function necessarily needs to be added (though if there aren't too many, maybe it would be nice to ensure no use case is excluded...?), but as I'm using Lily for 2D game development, I would find eg. atan2 to be quite useful when working with angles. Right now a bit more manual code is required to accomplish that with plain atan.

If I added in the rest (or at least most) of C99 functions it would be around 20 or more functions on top of what's already in this PR, not sure if that's considered overboard or not, personally myself I would be fine with it but I'm unsure of how others feel regarding this. as for atan2 my exclusion of it in this PR is because I'm not sure if Lily has any strong ideals/goals/preferences regarding naming of functions as the "2" in atan2 has a different meaning compared to the "2" in log2 and exp2 although if this/that isn't a concern ill probably include atan2 with it's name from C/C++ in another commit attached to this PR as the function itself is useful.

Additionally, while with bindings this simple this admittedly isn't all that critical, there should probably be tests for these new functions in test/prelude/test_pkg_math.lily.

Ah thanks for mentioning this, when I was doing a local search of the repo to make sure I didn't miss anywhere all .lily files where being excluded by mistake! This also explains why I couldn't find where the documentation for the math module was located. ill work on adding some simple tests and documentation, however if for whatever reason I somehow don't come back then I guess someone else could do it (not trying to create extra work for others just trying to cover all bases as life can be unpredictable).

You'll have to wait for @FascinatedBox for this, but do keep in mind it seems this GitHub repository is more or less just a mirror now. Active development/discussion is happening on GitLab.

Hopefully I don't have to move anything over myself as I personally struggle with tasks such as that which others find easy. I really wouldn't mind if someone ends up bringing this PR over manually if merging in from the GitHub repo itself is infeasible.

adds documentation and tests for the new math functions although the set of tests is in this commit is incomplete
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.

2 participants