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

LCM (support Rat and fail on lossy coercion) #55

Open
alabamenhu opened this issue Jun 28, 2019 · 0 comments
Open

LCM (support Rat and fail on lossy coercion) #55

alabamenhu opened this issue Jun 28, 2019 · 0 comments
Labels
language Changes to the Raku Programming Language

Comments

@alabamenhu
Copy link

The current definition of lcm coerces arguments to Int. This generates quite unexpected behavior when passed Rat which can have a defined LCM.

Suggestion

  1. Maintain current behavior if both arguments can be coerced to Int.
  2. If both arguments can be coerced to Rat, do the following:
-> Rat \a, Rat \b {
  (a.numerator lcm b.numerator) / (a.denominator gcd b.denominator)
} 
  1. Failing all else, fail. Lossy coercion will result in unexpected values. It is better to fail with π lcm e now (and support it later, if symbolic math were added to core) then to produce 6 (when it should be simple πe, or 8.53…). Users can always manually coerce if they want unexpected behavior.

Potential issues

  • Given 1.5 and 4.5, the above algorithm will generate 4.5 (9/2). Some users may want a whole LCM, but that is more trivially generated from the rational (just the numerator) than the opposite, I think.
  • Complex numbers can be calculated too, but if we fail now, support can be added later without potentially breaking code.
@AlexDaniel AlexDaniel added the language Changes to the Raku Programming Language label Jun 28, 2019
@lizmat lizmat unassigned jnthn Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

3 participants