Support Units in Ceil and Floor
The issues section is used only for bug reports. Please use the Discussions section to ask questions and share ideas and suggestions.
Describe the bug This is a feature request more of a bug, Seeing there are test's in place verify it is not supported, but I would like to be able to use ceil and floor on numbers with units,
For example evaluate('ceil( 10.42ft / 2 )')
To Reproduce evaluate('ceil( 10.42ft / 2 )')
Thanks for your feature request. We can indeed extend ceil, floor, and fix to support units, similar to round: https://github.com/josdejong/mathjs/pull/3095.
Anyone interested in implementing this?
Hello! How complex should this unit's evaluation be? For example, do we need to consider cases like evaluate('ceil( 10.42ft / 2m )') and will ceil to a selected unit? Or just a unified unit across the function.
I think your example 10.42ft / 2m results in number, which is already supported by ceil, so I think that doesn't make a difference.
The core here is to extend the functions ceil, floor, and fix with new signatures so they support:
ceil(x)
ceil(x, n)
ceil(unit, valuelessUnit) # to be implemented
ceil(unit, n, valuelessUnit) # to be implemented
floor(x)
floor(x, n)
floor(unit, valuelessUnit) # to be implemented
floor(unit, n, valuelessUnit) # to be implemented
fix(x)
fix(x, n)
fix(unit, valuelessUnit) # to be implemented
fix(unit, n, valuelessUnit) # to be implemented
I think your example
10.42ft / 2mresults in number, which is already supported byceil, so I think that doesn't make a difference.The core here is to extend the functions
ceil,floor, andfixwith new signatures so they support:ceil(x) ceil(x, n) ceil(unit, valuelessUnit) # to be implemented ceil(unit, n, valuelessUnit) # to be implemented floor(x) floor(x, n) floor(unit, valuelessUnit) # to be implemented floor(unit, n, valuelessUnit) # to be implemented fix(x) fix(x, n) fix(unit, valuelessUnit) # to be implemented fix(unit, n, valuelessUnit) # to be implemented
Hi Jos,
I gave it a try. Please take a look when you have a chance.
Thanks!
@josdejong I believe this issue can be closed now.
👍 you're right.