-
Notifications
You must be signed in to change notification settings - Fork 16
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 the modf
routine to the core language
#462
Comments
Have you got an opinion on what "core" would mean? For example, almost all "core" Raku routines are part of A few routines are part of "core" but not part of Other possibilities seem plausible. There could be routines, whether part of To compare the Raku and Python takes that seem particularly relevant to
Perhaps we might best be ultra conservative about expanding |
Yes, I do understand the difference, and my wish was always for it to be in the core language. Larry intentionally intended the language to be as large as it needs to be, and I believe 'modf' was over looked in the beginning. And that has been one of the strengths of Raku over Python: most everything you need is already there. |
modf
routine to the core language
Introduction
The Raku core library does not have a 'modf' routine. The routine is commonly found in many popular programming languages (including Python), but it was not included in the original Raku release.
I once proposed adding one and made an elementary start at it, but soon realized it is not a trivial task due to numerical issues (see closed Rakudo PR #4432). A proper implementation in Raku would use the power inherent in the language to handle very large numbers, and the returned parts should be correct for those numbers as input to 'modf'. The routine proposed in PR #4432 followed the basic implementation as found in C and C++ with some slight modifications to take advantage of existing Raku features. PR #4432 also included tests.
In the rest of this article I will present my current view on implementing the routine from the user's perspective.
General definition of
modf
in other languagesGiven a number, return the integral and fractional parts of the number (both parts as base 10 values).
If the number is an integer, return zero as the fractional part.
Both parts will have the sign of the input.
Additional features in Raku
The returned values will be in a
List
of two allomorphs.There will be two optional parameters to allow the caller to shape the return values.
Signature
where
end if needed, or round to the desired precision)
a decimal point and all following zeroes for zero values
Examples
The following table shows various input formats and what is expected
to be returned. Although not evident in the table, the allomorph
output values will be bracketed by the appropriate quoting style to
retain the string appearance as shown.
NC - no change from the default appearance
The text was updated successfully, but these errors were encountered: