mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

Support Units in Ceil and Floor

Open tholum opened this issue 1 year ago • 4 comments

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 )')

tholum avatar Jun 03 '24 20:06 tholum

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?

josdejong avatar Jun 04 '24 06:06 josdejong

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.

yaojiejia avatar Jun 20 '24 02:06 yaojiejia

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

josdejong avatar Jun 26 '24 09:06 josdejong

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

Hi Jos,

I gave it a try. Please take a look when you have a chance.

Thanks!

orelbn avatar Sep 22 '24 04:09 orelbn

@josdejong I believe this issue can be closed now.

orelbn avatar Jan 08 '25 18:01 orelbn

👍 you're right.

josdejong avatar Jan 09 '25 08:01 josdejong