/** * Raise this unit to a power. * * @param power * The power to raise this unit by. * @return The result of raising this unit by the power <code>power</code>. * The offset of this unit will be ignored; thus, for example * "celsius.myRaiseTo(2)" is equivalent to "kelvin.myRaiseTo(2)". * @throws RaiseException * Can't raise this unit to a power. */ // Ignore offset (e.g. "Cel2" == "K2") @Override protected Unit myRaiseTo(final int power) throws RaiseException { return getUnit().raiseTo(power); }
/** * Raise this unit to a power. * * @param power * The power to raise this unit by. * @return The result of raising this unit by the power <code>power</code>. * The offset of this unit will be ignored; thus, for example * "celsius.myRaiseTo(2)" is equivalent to "kelvin.myRaiseTo(2)". * @throws RaiseException * Can't raise this unit to a power. */ // Ignore offset (e.g. "Cel2" == "K2") @Override protected Unit myRaiseTo(final int power) throws RaiseException { return getUnit().raiseTo(power); }
/** * Raises this unit to a power. * * @param power * The power. * @return The result of raising this unit to the power. * @throws RaiseException * Can't raise this unit to a power. */ @Override protected Unit myRaiseTo(final int power) throws RaiseException { return new ScaledUnit(Math.pow(getScale(), power), getUnit().raiseTo( power)); }
/** * Raises this unit to a power. * * @param power * The power. * @return The result of raising this unit to the power. * @throws RaiseException * Can't raise this unit to a power. */ @Override protected Unit myRaiseTo(final int power) throws RaiseException { return new ScaledUnit(Math.pow(getScale(), power), getUnit().raiseTo( power)); }
myAssert(parser, "(m)(m)", m.multiplyBy(m)); myAssert(parser, "m/s/s", m.divideBy(s).divideBy(s)); myAssert(parser, "m2", m.raiseTo(2)); myAssert(parser, "m2.s", m.raiseTo(2).multiplyBy(s)); myAssert(parser, "m2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m^2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m s @ 5", m.multiplyBy(s).shiftTo(5.0)); myAssert(parser, "m2 s @ 5", m.raiseTo(2).multiplyBy(s).shiftTo(5)); myAssert(parser, "m2 s-1 @ 5", m.raiseTo(2).multiplyBy(s.raiseTo(-1)) .shiftTo(5)); myAssert(parser, "m s from 5", m.multiplyBy(s).shiftTo(5)); myAssert(parser, "3.14 m.s", m.multiplyBy(s).multiplyBy(3.14)); myAssert(parser, "1e9 (m)", m.multiplyBy(1e9)); myAssert(parser, "(m s)2", m.multiplyBy(s).raiseTo(2)); myAssert(parser, "m2.s-1", m.raiseTo(2).divideBy(s)); myAssert(parser, "m2 s^-1", m.raiseTo(2).divideBy(s)); myAssert(parser, "(m/s)2", m.divideBy(s).raiseTo(2)); myAssert(parser, "m2/s-1", m.raiseTo(2).divideBy(s.raiseTo(-1))); myAssert(parser, "m2/s^-1", m.raiseTo(2).divideBy(s.raiseTo(-1))); myAssert(parser, ".5 m/(.25 s)2", m.multiplyBy(.5).divideBy( s.multiplyBy(.25).raiseTo(2))); myAssert(parser, "m.m-1.m", m.multiplyBy(m.raiseTo(-1)).multiplyBy(m)); myAssert(parser, "2.0 m 1/2 s-1*(m/s^1)^-1 (1e9 m-1)(1e9 s-1)-1.m/s", m .multiplyBy(2).multiplyBy(1. / 2.).multiplyBy( s.raiseTo(-1)).multiplyBy( m.divideBy(s.raiseTo(1)).raiseTo(-1)) .multiplyBy(m.raiseTo(-1).multiplyBy(1e9)).multiplyBy( s.raiseTo(-1).multiplyBy(1e9).raiseTo(-1))
final public Unit powerExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { Unit unit; int exponent; unit = basicExpr(unitDB); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: case UINT: case RAISE: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case RAISE: jj_consume_token(RAISE); break; default: jj_la1[7] = jj_gen; ; } exponent = integer(); unit = unit.raiseTo(exponent); break; default: jj_la1[8] = jj_gen; ; } { if (true) return unit; } throw new Error("Missing return statement in function"); }
myAssert(parser, "(m)(m)", m.multiplyBy(m)); myAssert(parser, "m/s/s", m.divideBy(s).divideBy(s)); myAssert(parser, "m2", m.raiseTo(2)); myAssert(parser, "m2.s", m.raiseTo(2).multiplyBy(s)); myAssert(parser, "m2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m^2/s", m.raiseTo(2).divideBy(s)); myAssert(parser, "m s @ 5", m.multiplyBy(s).shiftTo(5.0)); myAssert(parser, "m2 s @ 5", m.raiseTo(2).multiplyBy(s).shiftTo(5)); myAssert(parser, "m2 s-1 @ 5", m.raiseTo(2).multiplyBy(s.raiseTo(-1)) .shiftTo(5)); myAssert(parser, "m s from 5", m.multiplyBy(s).shiftTo(5)); myAssert(parser, "3.14 m.s", m.multiplyBy(s).multiplyBy(3.14)); myAssert(parser, "1e9 (m)", m.multiplyBy(1e9)); myAssert(parser, "(m s)2", m.multiplyBy(s).raiseTo(2)); myAssert(parser, "m2.s-1", m.raiseTo(2).divideBy(s)); myAssert(parser, "m2 s^-1", m.raiseTo(2).divideBy(s)); myAssert(parser, "(m/s)2", m.divideBy(s).raiseTo(2)); myAssert(parser, "m2/s-1", m.raiseTo(2).divideBy(s.raiseTo(-1))); myAssert(parser, "m2/s^-1", m.raiseTo(2).divideBy(s.raiseTo(-1))); myAssert(parser, ".5 m/(.25 s)2", m.multiplyBy(.5).divideBy( s.multiplyBy(.25).raiseTo(2))); myAssert(parser, "m.m-1.m", m.multiplyBy(m.raiseTo(-1)).multiplyBy(m)); myAssert(parser, "2.0 m 1/2 s-1*(m/s^1)^-1 (1e9 m-1)(1e9 s-1)-1.m/s", m .multiplyBy(2).multiplyBy(1. / 2.).multiplyBy( s.raiseTo(-1)).multiplyBy( m.divideBy(s.raiseTo(1)).raiseTo(-1)) .multiplyBy(m.raiseTo(-1).multiplyBy(1e9)).multiplyBy( s.raiseTo(-1).multiplyBy(1e9).raiseTo(-1))
final public Unit powerExpr(UnitDB unitDB) throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { Unit unit; int exponent; unit = basicExpr(unitDB); switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case PLUS: case MINUS: case UINT: case RAISE: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { case RAISE: jj_consume_token(RAISE); break; default: jj_la1[7] = jj_gen; ; } exponent = integer(); unit = unit.raiseTo(exponent); break; default: jj_la1[8] = jj_gen; ; } { if (true) return unit; } throw new Error("Missing return statement in function"); }
/** * Divides this derived unit by another. * * @param that * The other unit. * @return The quotient of the two units. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { Unit result; if (dimension.getRank() == 0) { result = that.raiseTo(-1); } else { if (!(that instanceof DerivedUnit)) { result = that.divideInto(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension.divideBy(thatDimension)); } } return result; }
/** * Divides this derived unit by another. * * @param that * The other unit. * @return The quotient of the two units. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { Unit result; if (dimension.getRank() == 0) { result = that.raiseTo(-1); } else { if (!(that instanceof DerivedUnit)) { result = that.divideInto(this); } else { final UnitDimension thatDimension = ((DerivedUnit) that) .getDimension(); result = thatDimension.getRank() == 0 ? this : new DerivedUnitImpl(dimension.divideBy(thatDimension)); } } return result; }