Replies: 2 comments 1 reply
-
That's basically the logic that we have used until now. :) When one of the experiments required another math function, we added it as a builtin. Pull requests implementing further builtins would certainly be welcome! Feel free to open a PR even if it is incomplete, as it will allow us to start talking about the code.
In the long run, we'll likely want to stop using builtins for the math functions, because builtins are tricky to implement. There are plans underway to implement a module system and foreign function interface, and when those are implemented it might be easier to build a more complete math library. But in the meantime, implementing math functions as builtins is the way to go.
Right now, the only way to implement optional parameters is using the
I would look inside the lmathlib.c for inspiration. In particular, the math_log function. Generally speaking, we want our generated code to look similar to the code in the Lua standard library. That way we can make it behave the same way as Lua. For example, note that Lua uses the
Would it be a problem if math.abs only worked on floating point numbers? |
Beta Was this translation helpful? Give feedback.
-
Nice catch, that does sound like a bug! I think it would be appropriate to create a separate PR for that. |
Beta Was this translation helpful? Give feedback.
-
Hi, I was trying to implement some code for my little experiment project that depend on math library functions, specifically: exp, log, pow.
I figured out how to hack these into Pallene using sqrt as the template. It's not a lot of code, but would you like me to submit a pull request?
I should note that my math.log is not fully correct because I could only figure out how to support one parameter (mapping to C's log.) But I figure at the moment, this incomplete implementation is still no worse than no implementation. For two parameters, I haven't figured out:
Similarly, math.abs also needs to handle floats and integers differently (call fabs or abs (or is it labs)).
Thanks
Beta Was this translation helpful? Give feedback.
All reactions