-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 complex-numbers exercise #100
Conversation
Do you think this is too short? Complex : { re : F64, im : F64 } Should it be this instead? Complex : { real : F64, imaginary: F64 } This would mean functions like: div : Complex, Complex -> Complex
div = \z1, z2 ->
denominator = z2.real * z2.real + z2.imaginary * z2.imaginary
{
re: (z1.real * z2.real + z1.imaginary * z2.imaginary) / denominator,
im: (z1.imaginary * z2.real - z1.real * z2.imaginary) / denominator,
} instead of this: div : Complex, Complex -> Complex
div = \z1, z2 ->
denominator = z2.re * z2.re + z2.im * z2.im
{
re: (z1.re * z2.re + z1.im * z2.im) / denominator,
im: (z1.im * z2.re - z1.re * z2.im) / denominator,
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! I like the terse version personally, I think it is plenty clear and very pleasant to parse. Still many more characters than would be used to describe these operations in math notation 😄
I also considered destructuring: div : Complex, Complex -> Complex
div = \{real: a, imaginary: b}, {real: c, imaginary: d} ->
denominator = c * c + d * d
{
real: (a * c + b * d) / denominator,
imaginary: (b * c - a * d) / denominator,
} This might actually be nicer, wdyt? |
Actually, I've settled on the following, with the terse Edit: I merged this PR too fast, so the final improvements are in PR #102, sorry about that. |
Thanks again @isaacvando ! |
No description provided.