-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: adds unit support to ceil, floor, and fix functions #3269
feat: adds unit support to ceil, floor, and fix functions #3269
Conversation
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.
Thanks Orel! This is exactly what we're looking for, nice job. Thanks for updating all the docs and TypeScript types. The types run fine, they run via Github Actions of this PR and all checks are green.
I've made one inline comment, can you have a look at that?
Is there a restriction that the matrix or array must contain only units? I believe that to be the case. If so, I would like to update the types further. I would like to do it in a separate PR. |
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.
Thanks for the updates. I made two more comments, can you have a look at those?
Is there a restriction that the matrix or array must contain only units?
Matrices can contain mixed content of numbers, units, complex numbers etc. There is still an issue in that regard though: the type definitions currently do not allow to have a matrix containing units at all:
Line 16 in fb76ac4
export type MathArray = MathNumericType[] | MathNumericType[][] // TODO: MathArray can also contain Unit |
Maybe best to address that issue separately though.
Thank you for the clarification! Is the desired behaviour that matrices and arrays only contain units when the second or third argument to the For example, Line 1192 in 6bcb26c
Proposed new type definition:
|
That makes sense indeed! Can you refine the type definitions with your proposal? |
I played around with it a bit. This is what I believe the tasks that are required:
From a user perspective, if they create an array that contains multiple types they will get this error
They can use the utility (although slow since it has to go through. the entire array/matrix) or assert the type.
|
Thanks for the updates! The improved TypeScript support is awesome, and with the generic Two questions:
|
Sorry for the delayed response. Very busy this past week. All of your suggestions sound great. Thank you for the input 😄 ! I will remove the type guards and address your suggestion in a separate PR. I agree that there is definitely more thinking to do. Regarding the multiply, I will take a look again. After further look: Not all array operations are supported on unit arrays, so if we say that MathArrays can include units.
So what I can do for now is set the default to a MathNumerticType I will address the type guard sometime in the next couple of days. |
I did find a small error in one of the multiply function types. Would you like me to file an issue or fix it in one of the upcoming PRs? Error in function type: multiplication of two MathArrays does not necessarily result in a MathArray. Line 1364 in 07bff55
To Reproduce Multiply two single-dimensional arrays together, and the result is a number. |
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.
Thanks for the updates, I think we're there! I made one last small remark, can you have a look at that?
Good find about the wrong types when multiplying two vectors. In that case mathjs returns a scalar value, and not an array containing one value. Since this is not a regression introduced in this PR but an existing bug in the type definitions, I think it's best to create a separate PR improving the types for vector multiplication, ok?
I've had a thorough look at the changes in the type definitions. I expect the changes are not be breaking in normal, practical cases, but there may be tricky edge cases that have breaking behavior. To be careful in this regard, I would like to merge this PR into the next major version v14, ok? (I plan to release v14 "soonish", within a couple of weeks).
That sounds good. I will address the vector multiplication types separately. Adding the functionality in version 14 is completely fine with me. Thank you for the in-depth review 😄 |
Thanks! Merged now in the |
Published now in |
Description
Test
Additional Notes