Search in sources :

Example 1 with LogConverter

use of tech.units.indriya.function.LogConverter in project indriya by unitsofmeasurement.

the class LocalUnitFormatParser method ExponentExpr.

public final Unit ExponentExpr() throws TokenException {
    Unit result = AbstractUnit.ONE;
    Exponent exponent = null;
    Token token = null;
    if (jj_2_2(2147483647)) {
        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
            case INTEGER:
                token = consumeToken(INTEGER);
                break;
            case E:
                token = consumeToken(E);
                break;
            default:
                laA[5] = genInt;
                consumeToken(-1);
                throw new TokenException();
        }
        consumeToken(CARET);
        result = AtomicExpr();
        double base;
        if (token.kind == INTEGER) {
            base = Integer.parseInt(token.image);
        } else {
            base = StrictMath.E;
        }
        {
            return result.transform(new LogConverter(base).inverse());
        }
    } else {
        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
            case OPEN_PAREN:
            case INTEGER:
            case FLOATING_POINT:
            case UNIT_IDENTIFIER:
                result = AtomicExpr();
                switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                    case CARET:
                    case SUPERSCRIPT_INTEGER:
                        exponent = Exp();
                        break;
                    default:
                        laA[6] = genInt;
                }
                if (exponent != null) {
                    if (exponent.pow != 1) {
                        result = result.pow(exponent.pow);
                    }
                    if (exponent.root != 1) {
                        result = result.root(exponent.root);
                    }
                }
                {
                    return result;
                }
            case LOG:
            case NAT_LOG:
                switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                    case LOG:
                        consumeToken(LOG);
                        switch((nextTokenIndex == -1) ? jj_ntk() : nextTokenIndex) {
                            case INTEGER:
                                token = consumeToken(INTEGER);
                                break;
                            default:
                                laA[7] = genInt;
                        }
                        break;
                    case NAT_LOG:
                        token = consumeToken(NAT_LOG);
                        break;
                    default:
                        laA[8] = genInt;
                        consumeToken(-1);
                        throw new TokenException();
                }
                consumeToken(OPEN_PAREN);
                result = AddExpr();
                consumeToken(CLOSE_PAREN);
                double base = 10;
                if (token != null) {
                    if (token.kind == INTEGER) {
                        base = Integer.parseInt(token.image);
                    } else if (token.kind == NAT_LOG) {
                        base = StrictMath.E;
                    }
                }
                {
                    return result.transform(new LogConverter(base));
                }
            default:
                laA[9] = genInt;
                consumeToken(-1);
                throw new TokenException();
        }
    }
}
Also used : LogConverter(tech.units.indriya.function.LogConverter) Unit(javax.measure.Unit) AbstractUnit(tech.units.indriya.AbstractUnit)

Example 2 with LogConverter

use of tech.units.indriya.function.LogConverter in project indriya by unitsofmeasurement.

the class UnitFormatParser method exponentExpr.

@SuppressWarnings("unused")
Unit<?> exponentExpr() throws TokenException {
    Unit<?> result = AbstractUnit.ONE;
    Exponent exponent = null;
    Token token = null;
    if (jj_2_2(2147483647)) {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case INTEGER:
                token = jj_consume_token(INTEGER);
                break;
            case E:
                token = jj_consume_token(E);
                break;
            default:
                jj_la1[5] = jj_gen;
                jj_consume_token(-1);
                throw new TokenException();
        }
        jj_consume_token(CARET);
        result = atomicExpr();
        double base;
        if (token.kind == INTEGER) {
            base = Integer.parseInt(token.image);
        } else {
            base = E;
        }
        {
            if (true)
                return result.transform(new LogConverter(base).inverse());
        }
    } else {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case OPEN_PAREN:
            case INTEGER:
            case FLOATING_POINT:
            case UNIT_IDENTIFIER:
                result = atomicExpr();
                switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                    case CARET:
                    case SUPERSCRIPT_INTEGER:
                        exponent = exp();
                        break;
                    default:
                        jj_la1[6] = jj_gen;
                }
                if (exponent != null) {
                    if (exponent.pow != 1) {
                        result = result.pow(exponent.pow);
                    }
                    if (exponent.root != 1) {
                        result = result.root(exponent.root);
                    }
                }
                {
                    if (true)
                        return result;
                }
            // break;
            case LOG:
            case NAT_LOG:
                switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                    case LOG:
                        jj_consume_token(LOG);
                        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                            case INTEGER:
                                token = jj_consume_token(INTEGER);
                                break;
                            default:
                                jj_la1[7] = jj_gen;
                        }
                        break;
                    case NAT_LOG:
                        token = jj_consume_token(NAT_LOG);
                        break;
                    default:
                        jj_la1[8] = jj_gen;
                        jj_consume_token(-1);
                        throw new TokenException();
                }
                jj_consume_token(OPEN_PAREN);
                result = addExpr();
                jj_consume_token(CLOSE_PAREN);
                double base = 10;
                if (token != null) {
                    if (token.kind == INTEGER) {
                        base = Integer.parseInt(token.image);
                    } else if (token.kind == NAT_LOG) {
                        base = E;
                    }
                }
                {
                    if (true)
                        return result.transform(new LogConverter(base));
                }
            default:
                jj_la1[9] = jj_gen;
                jj_consume_token(-1);
                throw new TokenException();
        }
    }
    throw new Error("Missing return statement in function");
}
Also used : LogConverter(tech.units.indriya.function.LogConverter)

Example 3 with LogConverter

use of tech.units.indriya.function.LogConverter in project indriya by unitsofmeasurement.

the class LogConverterTest method testGetValueLogConverter.

@Test
public void testGetValueLogConverter() {
    LogConverter logConverter = new LogConverter(Math.E);
    assertEquals("Log(10.0)", logConverterBase10.getValue());
    assertEquals("ln", logConverter.getValue());
}
Also used : LogConverter(tech.units.indriya.function.LogConverter) Test(org.junit.jupiter.api.Test)

Example 4 with LogConverter

use of tech.units.indriya.function.LogConverter in project indriya by unitsofmeasurement.

the class ExpConverterTest method inverseLogTest.

@Test
public void inverseLogTest() {
    ExpConverter expConverter = ExpConverter.of(Math.E);
    assertEquals(new LogConverter(10.), expConverterBase10.inverse());
    assertEquals(new LogConverter(Math.E), expConverter.inverse());
}
Also used : LogConverter(tech.units.indriya.function.LogConverter) ExpConverter(tech.units.indriya.function.ExpConverter) Test(org.junit.jupiter.api.Test)

Example 5 with LogConverter

use of tech.units.indriya.function.LogConverter in project indriya by unitsofmeasurement.

the class ExpConverterTest method convertLogTest.

@Test
public void convertLogTest() {
    LogConverter logConverter = new LogConverter(10.);
    assertEquals(1.0, logConverter.convert(expConverterBase10.convert(1.0)));
    assertEquals(-10, logConverter.convert(expConverterBase10.convert(-10)));
}
Also used : LogConverter(tech.units.indriya.function.LogConverter) Test(org.junit.jupiter.api.Test)

Aggregations

LogConverter (tech.units.indriya.function.LogConverter)7 Test (org.junit.jupiter.api.Test)5 ExpConverter (tech.units.indriya.function.ExpConverter)2 Unit (javax.measure.Unit)1 AbstractUnit (tech.units.indriya.AbstractUnit)1