Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

In this page you can find the example usage for java.lang Math pow.

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:SpinnerSelectionListener.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);/*from  w  ww . ja  v  a2 s  .  c  o m*/
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);

    spinner.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selection = spinner.getSelection();
            int digits = spinner.getDigits();
            System.out.println("Selection is " + (selection / Math.pow(10, digits)));
        }
    });

    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7));
    System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0));
    System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7));
    System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2));
    System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8));
    System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0));
    System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0));
    System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0));
    System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2));
    System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8));
    System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E));
    System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E));
    System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7));
    System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7));
    System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7));
    System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7));
    System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0));
    System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5));
    System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0));
    System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0));
    System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0));
    System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0));
}

From source file:Snippet190.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);//  w w w  .java 2  s .c om
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);
    spinner.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selection = spinner.getSelection();
            int digits = spinner.getDigits();
            System.out.println("Selection is " + (selection / Math.pow(10, digits)));
        }
    });
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet190.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);/*from  ww  w  .j a  va 2  s .  c  om*/
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);
    spinner.addSelectionListener(widgetSelectedAdapter(e -> {
        int selection = spinner.getSelection();
        int digits = spinner.getDigits();
        System.out.println("Selection is " + (selection / Math.pow(10, digits)));
    }));
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:CompressTransfer.java

public static void main(String[] args) throws Exception {
    String file = "e:\\46294_20131121_w3c.gz";
    String to = "e:\\46294_20131121_w3c.bz2";
    //decompress(new FileInputStream(file),System.out);
    long start = System.nanoTime();
    transfer(new FileInputStream(file), new FileOutputStream(to));
    System.out.print((System.nanoTime() - start) / Math.pow(10, 9));
}

From source file:ExponentialDemo.java

public static void main(String[] args) {
    double x = 11.635;
    double y = 2.76;

    System.out.printf("The value of e is %.4f%n", Math.E);
    System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x));
    System.out.printf("log(%.3f) is %.3f%n", x, Math.log(x));
    System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));
    System.out.printf("sqrt(%.3f) is %.3f%n", x, Math.sqrt(x));
}

From source file:ExponentialDemo.java

public static void main(String[] args) {
    double x = 11.635;
    double y = 2.76;

    System.out.println("The value of e is " + Math.E);
    System.out.println("exp(" + x + ") is " + Math.exp(x));
    System.out.println("log(" + x + ") is " + Math.log(x));
    System.out.println("pow(" + x + ", " + y + ") is " + Math.pow(x, y));
    System.out.println("sqrt(" + x + ") is " + Math.sqrt(x));
}

From source file:com.wormsim.LaunchFromCodeMain.java

public static void main(String[] args) throws IOException {
    // TODO: Move this from utils into SimulationCommands itself.
    SimulationCommands cmds = Utils.readCommandLine(args);
    SimulationOptions ops = new SimulationOptions(cmds);

    // Change options here.
    ops.checkpoint_no.set(CHECKPOINT_NUMBER);
    ops.thread_no.set(3);//  w  ww .ja  v  a2s  . c o  m
    ops.assay_iteration_no.set(100);
    ops.burn_in_no.set(20000);
    ops.record_no.set(40000);
    ops.detailed_data.set(Boolean.TRUE);
    ops.walker_no.set(32);
    ops.pheromone_no.set(1);
    ops.forced_run.set(Boolean.TRUE);
    ops.initial_conditions.set(makeCustomInitialConditions());
    ops.animal_zoo.set(makeCustomAnimalZoo(ops));

    // TODO: Add in the options for additional tracked values.
    if (ops.isMissingParameters()) {
        String msg = "Missing Parameters: " + ops.getMissingParametersList();
        LOG.log(Level.SEVERE, msg);
        System.exit(-1);
    } else {
        new Simulation(ops, new TrackedCalculation("Fitness", ops) {
            @Override
            protected double added(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value
                        + (p_group.getAnimalStage().toString().contains("Dauer") ? p_group.getCount() : 0.0);
            }

            @Override
            protected double end(SimulationThread.SamplingInterface p_iface, double p_prev_value) {
                return Math.pow(p_prev_value, 2);
            }

            @Override
            protected double ended(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value;
            }

            @Override
            protected double initialise(RandomGenerator p_rng) {
                return 0.0;
            }

            @Override
            protected double removed(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value;
            }
        }, new TrackedCalculation[] { new TrackedCalculation("Dauers", ops) {
            @Override
            protected double added(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value
                        + (p_group.getAnimalStage().toString().contains("Dauer") ? p_group.getCount() : 0.0);
            }

            @Override
            protected double end(SimulationThread.SamplingInterface p_iface, double p_prev_value) {
                return p_prev_value;
            }

            @Override
            protected double ended(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value;
            }

            @Override
            protected double initialise(RandomGenerator p_rng) {
                return 0.0;
            }

            @Override
            protected double removed(SimulationThread.SamplingInterface p_iface, AnimalGroup p_group,
                    double p_prev_value) {
                return p_prev_value;
            }
        } }).run();
    }
}

From source file:jsdp.app.control.clqg.univariate.CLQG.java

public static void main(String args[]) {

    /*******************************************************************
     * Problem parameters//ww  w  .  j ava2s.c o  m
     */

    int T = 20; // Horizon length
    double G = 1; // Input transition
    double Phi = 1; // State transition
    double R = 1; // Input cost
    double Q = 1; // State cost
    double Ulb = -1; // Action constraint
    double Uub = 20; // Action constraint
    double noiseStd = 5; // Standard deviation of the noise

    double[] noiseStdArray = new double[T];
    Arrays.fill(noiseStdArray, noiseStd);
    double truncationQuantile = 0.975;

    // Random variables

    Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(noiseStdArray.length)
            .mapToObj(i -> new NormalDist(0, noiseStdArray[i]))

            .toArray(Distribution[]::new);
    double[] supportLB = IntStream.iterate(0, i -> i + 1).limit(T)
            .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], 1 - truncationQuantile)).toArray();

    double[] supportUB = IntStream.iterate(0, i -> i + 1).limit(T)
            .mapToDouble(i -> NormalDist.inverseF(0, noiseStdArray[i], truncationQuantile)).toArray();

    double initialX = 0; // Initial state

    /*******************************************************************
     * Model definition
     */

    // State space

    double stepSize = 0.5; //Stepsize must be 1 for discrete distributions
    double minState = -25;
    double maxState = 100;
    StateImpl.setStateBoundaries(stepSize, minState, maxState);

    // Actions

    Function<State, ArrayList<Action>> buildActionList = (Function<State, ArrayList<Action>> & Serializable) s -> {
        StateImpl state = (StateImpl) s;
        ArrayList<Action> feasibleActions = new ArrayList<Action>();
        double maxAction = Math.min(Uub, (StateImpl.getMaxState() - Phi * state.getInitialState()) / G);
        double minAction = Math.max(Ulb, (StateImpl.getMinState() - Phi * state.getInitialState()) / G);
        for (double actionPointer = minAction; actionPointer <= maxAction; actionPointer += StateImpl
                .getStepSize()) {
            feasibleActions.add(new ActionImpl(state, actionPointer));
        }
        return feasibleActions;
    };

    Function<State, Action> idempotentAction = (Function<State, Action> & Serializable) s -> new ActionImpl(s,
            0.0);

    ImmediateValueFunction<State, Action, Double> immediateValueFunction = (initialState, action,
            finalState) -> {
        ActionImpl a = (ActionImpl) action;
        StateImpl fs = (StateImpl) finalState;
        double inputCost = Math.pow(a.getAction(), 2) * R;
        double stateCost = Math.pow(fs.getInitialState(), 2) * Q;
        return inputCost + stateCost;
    };

    // Random Outcome Function

    RandomOutcomeFunction<State, Action, Double> randomOutcomeFunction = (initialState, action, finalState) -> {
        double realizedNoise = ((StateImpl) finalState).getInitialState()
                - ((StateImpl) initialState).getInitialState() * Phi - ((ActionImpl) action).getAction() * G;
        return realizedNoise;
    };

    /*******************************************************************
     * Solve
     */

    // Sampling scheme

    SamplingScheme samplingScheme = SamplingScheme.NONE;
    int maxSampleSize = 50;
    double reductionFactorPerStage = 1;

    // Value Function Processing Method: backward recursion
    double discountFactor = 1.0;
    int stateSpaceLowerBound = 10000000;
    float loadFactor = 0.8F;
    BackwardRecursionImpl recursion = new BackwardRecursionImpl(OptimisationDirection.MIN, distributions,
            supportLB, supportUB, immediateValueFunction, randomOutcomeFunction, buildActionList,
            idempotentAction, discountFactor, samplingScheme, maxSampleSize, reductionFactorPerStage,
            stateSpaceLowerBound, loadFactor, HashType.THASHMAP);

    System.out.println("--------------Backward recursion--------------");
    StopWatch timer = new StopWatch();
    OperatingSystemMXBean osMBean;
    try {
        osMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
                ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
        long nanoBefore = System.nanoTime();
        long cpuBefore = osMBean.getProcessCpuTime();

        timer.start();
        recursion.runBackwardRecursionMonitoring();
        timer.stop();

        long cpuAfter = osMBean.getProcessCpuTime();
        long nanoAfter = System.nanoTime();

        long percent;
        if (nanoAfter > nanoBefore)
            percent = ((cpuAfter - cpuBefore) * 100L) / (nanoAfter - nanoBefore);
        else
            percent = 0;

        System.out.println(
                "Cpu usage: " + percent + "% (" + Runtime.getRuntime().availableProcessors() + " cores)");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println();
    double ETC = recursion.getExpectedCost(initialX);
    StateDescriptorImpl initialState = new StateDescriptorImpl(0, initialX);
    double action = recursion.getOptimalAction(initialState).getAction();
    System.out.println("Expected total cost (assuming an initial state " + initialX + "): " + ETC);
    System.out.println("Optimal initial action: " + action);
    System.out.println("Time elapsed: " + timer);
    System.out.println();
}

From source file:com.quest.orahive.HiveJdbcClient.java

public static void main(String[] args) {

    long mainStartTime = System.nanoTime();

    Configuration conf = new Configuration();
    Options options = new Options();

    parseGeneralOptions(options, conf, args); //<- log4j will now be configured.

    showWelcomeMessage();//from w  w  w.  j  av  a2 s. c  o m

    if (args.length == 0 || userWantsToSeeHelp(args)) {
        printCommandLineHelp(options);
        System.exit(0);
    }

    checkConfiguration(conf);

    OraHiveOptions opts = getOraHiveOptions(conf);
    OraHiveCounters counters = new OraHiveCounters();

    try {
        Connection hiveConnection = createHiveJdbcConnection(opts.hiveJdbcUrl, opts.hiveUserName,
                opts.hivePassword);
        try {
            Connection oracleConnection = createOracleJdbcConnection(opts.oracleJdbcUrl, opts.oracleUserName,
                    opts.oraclePassword);
            try {
                initializeOracleSession(oracleConnection, opts);

                Statement statement = hiveConnection.createStatement();

                LOG.info("Running: " + opts.hql);

                // Execute Hive Query...
                long start = System.nanoTime();
                ResultSet hiveResultSet = statement.executeQuery(opts.hql);
                counters.hiveQueryTimeNanoSec = System.nanoTime() - start;

                // Get column definitions from the Hive resultset...
                List<OracleTableColumn> oracleColumns = getOracleTableColumnsForHiveResults(hiveResultSet);

                if (opts.exportMode.equals(Constants.ExportMode.CREATE)) {
                    // Create an Oracle table based on the columns in the Hive resultset...
                    createOracleTableWithRetry(opts, oracleColumns, oracleConnection); //<- Lets the user retry this if it fails.
                }

                // Generate the Oracle insert statement...
                String insertSql = generateOracleInsertStatement(opts, oracleColumns);

                // Insert the Hive data into Oracle...
                insertHiveResultsIntoOracleTable(opts, insertSql, oracleColumns, oracleConnection,
                        hiveResultSet, counters);

                //hiveResultSet.close();   //<- Not required/supported
                statement.close();
            } finally {
                oracleConnection.close();
            }
        } finally {
            hiveConnection.close();
        }

    } catch (SQLException ex) {
        LOG.error(String.format("An error occurred in %s.", Constants.ORAHIVE_PRODUCT_NAME), ex);
    }

    LOG.info(String.format("\n\n********************************************************************\n"
            + "\tTotal time                        : %s sec.\n" + "\tNumber of records processed       : %s\n"
            + "\tTime spent executing HQL statement: %s sec.\n"
            + "\tTime spent fetching Hive data     : %s sec.\n"
            + "\tTime spent inserting into Oracle  : %s sec.",
            (System.nanoTime() - mainStartTime) / Math.pow(10, 9), counters.rowsProcessed,
            counters.hiveQueryTimeNanoSec / Math.pow(10, 9), counters.hiveFetchTimeNanoSec / Math.pow(10, 9),
            counters.oracleInsertTimeNanoSec / Math.pow(10, 9)));

}