/* (non-Javadoc)
@see net.finmath.stochastic.RandomVariable#pow(double)
492697
@Override
	public RandomVariable pow(double exponent) {
		return apply(OperatorType.POW, new RandomVariable[]{this, constructNewAADRandomVariable(exponent)});
	}
1329716
@Override
  public void evaluate(DoubleSolution solution) {
    double [] f = new double[getNumberOfObjectives()];
    f[0] = solution.getVariableValue(0) ;
    f[1] = (1.0 + solution.getVariableValue(1))/solution.getVariableValue(0);
    
    solution.setObjective(0,f[0]);
    solution.setObjective(1,f[1]);

    this.evaluateConstraints(solution);
  }
1194211
public static double[] pow(double[] x, double n) {
        double[] array = new double[x.length];
        for (int i = 0; i < x.length; i++) {
            array[i] = Math.pow(x[i], n);
        }
        return array;
    }
963169
@Override
	public RandomVariable add(RandomVariable randomVariable) {
		if(randomVariable.getTypePriority() > this.getTypePriority()) {
			// Check type priority
			return randomVariable.add(this);
		}

		// Set time of this random variable to maximum of time with respect to which measurability is known.
		double newTime = Math.max(time, randomVariable.getFiltrationTime());

		if(isDeterministic() && randomVariable.isDeterministic()) {
			double newValueIfNonStochastic = valueIfNonStochastic + randomVariable.get(0);
			return new RandomVariableFromDoubleArray(newTime, newValueIfNonStochastic);
		}
		else if(isDeterministic()) {
			double[] newRealizations = new double[Math.max(size(), randomVariable.size())];
			for(int i=0; i<newRealizations.length; i++) {
				newRealizations[i]		 = valueIfNonStochastic + randomVariable.get(i);
			}
			return new RandomVariableFromDoubleArray(newTime, newRealizations);
		} else {
			double[] newRealizations = new double[Math.max(size(), randomVariable.size())];
			for(int i=0; i<newRealizations.length; i++) {
				newRealizations[i]		 = realizations[i] + randomVariable.get(i);
			}
			return new RandomVariableFromDoubleArray(newTime, newRealizations);
		}
	}
216298
@Pure
	@Inline(value = "$3.pow($1.floatValue(), $2)", imported = Math.class)
	public static double operator_power(Float left, long right) {
		return Math.pow(left.floatValue(), right);
	}
245726
public static double getDouble(
    Object      value)
  {
    if (value == null)
    {
        return 0;
    }

    return Double.valueOf(value.toString()).doubleValue();

  }
1010351
public static long pow(long b, int k) {
        checkNonNegative("exponent", k);
        if (-2 <= b && b <= 2) {
            switch ((int) b) {
                case 0:
                    return (k == 0) ? 1 : 0;
                case 1:
                    return 1;
                case (-1):
                    return ((k & 1) == 0) ? 1 : -1;
                case 2:
                    return (k < Long.SIZE) ? 1L << k : 0;
                case (-2):
                    if (k < Long.SIZE) {
                        return ((k & 1) == 0) ? 1L << k : -(1L << k);
                    } else {
                        return 0;
                    }
                default:
                    throw new AssertionError();
            }
        }
        for (long accum = 1;; k >>= 1) {
            switch (k) {
                case 0:
                    return accum;
                case 1:
                    return accum * b;
                default:
                    accum *= ((k & 1) == 0) ? 1 : b;
                    b *= b;
            }
        }
    }
323801
public SDVariable pow(SDVariable x, SDVariable y) {
        return pow(null, x, y);
    }
938885
public JBBPOut Double(final double... value) throws IOException {
    assertNotEnded();
    assertArrayNotNull(value);
    if (this.processCommands) {
      for (final double d : value) {
        _writeDouble(d);
      }
    }
    return this;
  }
432385
@Override
	public double getStandardDeviation(RandomVariable probabilities) {
		if(isDeterministic()) {
			return 0.0;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		return Math.sqrt(getVariance(probabilities));
	}
8944
public static NumberExpression<Double> random(int seed) {
        return Expressions.numberOperation(Double.class, MathOps.RANDOM2, ConstantImpl.create(seed));
    }
1297223
static double powerOfTwoD(int n) {
        assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
        return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
                                        (DoubleConsts.SIGNIFICAND_WIDTH-1))
                                       & DoubleConsts.EXP_BIT_MASK);
    }
851288
public static double pow(double a, double b)
    {

        /*
         * Wright out a^b as 2^(b log2(a)) and then replace a with 'm 2^e' to get
         * 2^(b * log2(m*2^e)) which simplifies to 
         * m^b 2^(b e) when m, e, and b are positive. 
         * 
         * m & e are by IEEE defintion positive 
         */

        if (b < 0)
            return 1 / pow(a, -b);//b is now made positive

        long rawBits_a = doubleToLongBits(a);
        long mantissa_a = getMantissa(rawBits_a);
        final int e_a = Math.getExponent(a);

        //compute m^b and exploit the fact that we know there is no need for the exponent
        double m = longBitsToDouble(1023L << 52 | mantissa_a);//m in [1, 2]
        
        final double log2m = 1.790711564253215 + 0.248597253161674 * m - 3.495545043418375 / (0.714309275671154 + 1.000000000000000 * m);

        //we end up with 2^(b * log_2(m)) * 2^(b * e), which we can reduce to a single pow2 call
        return pow2(b * log2m + b * e_a);//fun fact, double*int is faster than casting an int to a double...
    }
759058
@Pure
	@Inline(value="$3.pow($1, $2)", imported=Math.class)
	public static double operator_power(char a, int b) {
		return Math.pow(a, b);
	}
537179
public static double randomDouble(double min, double max, int scale, RoundingMode roundingMode) {
		return NumberUtil.round(randomDouble(min, max), scale, roundingMode).doubleValue();
	}
646210
@Inline(value="$1.pow($2)")
	@Pure
	public static BigInteger operator_power(BigInteger a, int exponent) {
		return a.pow(exponent);
	}
852370
@Override
	public RandomVariable add(double value) {
		return apply(OperatorType.ADD, new RandomVariable[]{this, constructNewAADRandomVariable(value)});
	}