unitsofmeasurement / unit-api

Units of Measurement API
http://unitsofmeasurement.github.io/unit-api/
Other
180 stars 42 forks source link

Rational Prefix? #196

Closed keilw closed 5 years ago

keilw commented 5 years ago

When checking out other international prefixes, I came across fractions, that do not simply deal with an exponent like https://en.wikipedia.org/wiki/Tamil_units_of_measurement#Fractions For example 1/2= 0.5 – அரை – arai which would be a RationalNumber.of(1, 2) using Indriya.

UCAR Units has this Prefix with a conversion factor that is a double. Would it be an option to have a numeric method like getValue() or getFactor() in Prefix, too?

keilw commented 5 years ago

If it's not too vague we could also use java.util.function.Supplier<Number> instead.

keilw commented 5 years ago

@andi-huber What do you think, it's not just used by Tamil or other exotic prefixes, think of the "Quarterpounder".

keilw commented 5 years ago

Actually the least invasive approach seems like adding a numeric method getValue() instead of getBase() (nothing restricts the base from being a floating point number, BigDecimal also has a pow() method) and allow MultiplyConverter to decide whether to create a RationalConverter, PowerofIntConverter (which probably better be called IntPowerConverter now, we have drastically reduced cohesion here, so we can rename it) So we don't have to fumble with a type or other categorization. If exponent is 1, it'll have no effect and the number can be treated like rational value.

andi-huber commented 5 years ago

Would it be an option to have a numeric method like getValue() or getFactor() in Prefix, too?

This would make sense from my perspective, yes. Use Number to replace double, if possible or otherwise at least allow for a Prefix to be defined by a 'scaling factor' of type Number as an alternative to double.

keilw commented 5 years ago

Ok, will have a look at it tonight or tomorrow after our talk. Thanks

teobais commented 5 years ago

@keilw I guess your last comment implies you will be working on it.

keilw commented 5 years ago

It's mostly done already ;-)